N
Nuxt6mo ago
Martial

Throwing and catching errors in CF workers

I have an server endpoint in which I throw an error:
throw createError({
statusMessage: "Invalid password",
statusCode: 400,
});
throw createError({
statusMessage: "Invalid password",
statusCode: 400,
});
Now I catch this error in my page with the below code. It works perfectly fine during development. But in production (cloudflare workers), error.statusMessage is undefined. Do you have an idea why ?
try {
await $fetch("/api/login/password/signin", {
method: "POST",
body: formData,
});
} catch (error) {
let message = "Unknown error";
const message = error instanceof FetchError ? error.statusMessage : "Unknown error";
toast.add({title: message});
}
try {
await $fetch("/api/login/password/signin", {
method: "POST",
body: formData,
});
} catch (error) {
let message = "Unknown error";
const message = error instanceof FetchError ? error.statusMessage : "Unknown error";
toast.add({title: message});
}
1 Reply
Martial
MartialOP6mo ago
error.data.statusMessage works also in prod so I'll use that.
Want results from more Discord servers?
Add your server