Uncaught (in promise) error
# workers-help
s
Hey, I'm tryna make a file uploading system. My full code is https://pastebin.com/dUCApxp4, but this should be the important part:```ts export default { async fetch(request, env) { const url = new URL(request.url); const key = url.pathname.slice(1); const { pathname } = new URL(request.url); if(pathname == "/") { return new Response("CDN is working! :D") } switch (request.method) { case 'PUT': if(request.headers["Authorization"] != "nop!") return "no, go away" await env.data.put(key, request.body, { customMetadata: Record({"uploader":request.headers["Author"]}) }); return "helo mate" ...``` However, when I sent a
PUT
request with the valid headers and data, it returns 500, and the logs show
Uncaught (in promise) TypeError: Incorrect type for Promise: the Promise did not resolve to 'Response'.
. I've been trying to fix this for a very long time, so any help would be appreciated!
k
return new Response("helo mate")
You're just returning a string, not a Response
s
Ah yep, I changed that to be a string, thinking that might be the issue. Changing it back now didn't fix the issue however
This is the next part (for getting files) and it works fine:

https://cdn.discordapp.com/attachments/1105516065284444250/1105516866430050394/image.png

k
return "no, go away"
is also wrong
s
oop that may be it
d
in the second to last line, you are returning
"helo mate"
, a string - which should be
return new Response("helo mate")
that was rather slow to send, thanks discord
s
\:P
ah yeah that fixed the issue! tysm!
well it fixed that issue
I assume its me being dumb because I've never used records before, but it's now a
Copy code
worker.js:15 Uncaught (in promise) ReferenceError: Record is not defined
    at Object.fetch (worker.js:15:27)
d
Record only exists as a type in TS, you construct one with just
{}
you might be thinking of `Map`s?
s
oop i really need to brush up on my ts, innit mate
thanks!
finally all works, woohoo
d
glad you got it working!