Auth hook, I can't change the error response
Aim
I need to show the different error messages depending on the different error scenarios. But I can't do this, because Supabase's error response is always the same:
{"code":"unexpected_failure","message":"error invoking hook"}{"code":"unexpected_failure","message":"error invoking hook"}.
My edge function:
Deno.serve(async (req) => {
try {
await sendSms(sms?.phone, messageBody);
return new Response(JSON.stringify({
success: true
}), {
status: 200,
headers: {
"Content-Type": "application/json"
}
});
} catch (error) {
if (error && error.httpCode === 422) {
// console.log('442'); // <-- I see this being logged
return new Response(JSON.stringify({
error: {
http_code: 422,
message: "SMS is not currently supported in this region."
}
}), {
status: 422,
headers: {
"Content-Type": "application/json"
}
});
// but the UI still receives the error below, which is not enough to distinguish between different error scenarios
// {"code":"unexpected_failure","message":"error invoking hook"}
}
return new Response("Internal Server Error", {
status: 500
});
}
});Deno.serve(async (req) => {
try {
await sendSms(sms?.phone, messageBody);
return new Response(JSON.stringify({
success: true
}), {
status: 200,
headers: {
"Content-Type": "application/json"
}
});
} catch (error) {
if (error && error.httpCode === 422) {
// console.log('442'); // <-- I see this being logged
return new Response(JSON.stringify({
error: {
http_code: 422,
message: "SMS is not currently supported in this region."
}
}), {
status: 422,
headers: {
"Content-Type": "application/json"
}
});
// but the UI still receives the error below, which is not enough to distinguish between different error scenarios
// {"code":"unexpected_failure","message":"error invoking hook"}
}
return new Response("Internal Server Error", {
status: 500
});
}
});