Express ish Next js API routes

Express-ish, Next.js API-routes
4 Replies
ale
ale•2y ago
will create a thread so we can keep the channel tidy. I was able to replicate the CORS error that you saw. However, at least in my case, a 403 also happened and, as you mentioned, removing the hash sums validations, it gets resolved. So yes, you do get an error when there is a hash mismatch, but it seems that the response might be missing some CORS headers that would allow you to see it in a normal response. I can suggest wrapping the fetch within a try/catch block so you can define what to do if these requests fail.
let res;
try {
res = await fetch(prefetchURL, {body:object ,method:'PUT'})
} catch (err) {
// Error handling in case of failure to upload object
}
let res;
try {
res = await fetch(prefetchURL, {body:object ,method:'PUT'})
} catch (err) {
// Error handling in case of failure to upload object
}
I'll also ask internally on why these errors don't seem to have the same Access-Control-Allow-Origin as the Bucket's CORS policy
daniel_klungo
daniel_klungoOP•2y ago
Thank you for getting back to me on this, and for asking internally about CORS for the errors. I'll definitely wrap the requests in try/catch blocks too, but in this case, I think checking res.ok is also a good idea since I don't believe the request actually throws in case of a 403
ale
ale•2y ago
fetch can throw exceptions (https://developer.mozilla.org/en-US/docs/Web/API/fetch#exceptions) you can reproduce it running the following code:
const f = async () => {try { await fetch('https://cloudflare.com')} catch (e) { console.log('err')} };
f();
const f = async () => {try { await fetch('https://cloudflare.com')} catch (e) { console.log('err')} };
f();
But yes, it's just a suggestion (:
daniel_klungo
daniel_klungoOP•2y ago
wat, TIL ! thank you 🙂
Want results from more Discord servers?
Add your server