Uncaught (in promise) error

Hey, I'm tryna make a file uploading system. My full code is https://pastebin.com/dUCApxp4, but this should be the important part:
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"
...
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!
10 Replies
kian
kian2y ago
return new Response("helo mate") You're just returning a string, not a Response
Silabear
SilabearOP2y ago
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
Silabear
SilabearOP2y ago
This is the next part (for getting files) and it works fine:
kian
kian2y ago
return "no, go away" is also wrong
Silabear
SilabearOP2y ago
oop that may be it
DaniFoldi
DaniFoldi2y ago
in the second to last line, you are returning "helo mate", a string - which should be return new Response("helo mate")lul that was rather slow to send, thanks discord
Silabear
SilabearOP2y ago
: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
worker.js:15 Uncaught (in promise) ReferenceError: Record is not defined
at Object.fetch (worker.js:15:27)
worker.js:15 Uncaught (in promise) ReferenceError: Record is not defined
at Object.fetch (worker.js:15:27)
DaniFoldi
DaniFoldi2y ago
Record only exists as a type in TS, you construct one with just {} you might be thinking of Maps?
Silabear
SilabearOP2y ago
oop i really need to brush up on my ts, innit mate thanks! finally all works, woohoo
DaniFoldi
DaniFoldi2y ago
meowparty glad you got it working!
Want results from more Discord servers?
Add your server