S
Supabase4mo ago
Idris

Meaningless errors from supabase edge functions

In my edge function i throw a error like this:
return new Response(
JSON.stringify({
error: {
http_code: errorCode,
message: errorMessage
}
}),
{
status: errorCode,
headers: { ...corsHeaders, 'Content-Type': 'application/json' }
}
);
return new Response(
JSON.stringify({
error: {
http_code: errorCode,
message: errorMessage
}
}),
{
status: errorCode,
headers: { ...corsHeaders, 'Content-Type': 'application/json' }
}
);
In my app I catch it
const { data, error } = await supabase.functions.invoke('user-management/create-user', {
body: requestData
});

if (error) {
console.log(error);
const { data, error } = await supabase.functions.invoke('user-management/create-user', {
body: requestData
});

if (error) {
console.log(error);
but the errors are very meaningless its always FunctionsHttpError: Edge Function returned a non-2xx status code How can I get a usefull error from the SDK, so the message of the error.| The response does correctly contain the error if i look in the network tab
{
"error": {
"http_code": 500,
"message": "A user with this email address has already been registered"
}
}
{
"error": {
"http_code": 500,
"message": "A user with this email address has already been registered"
}
}
3 Replies
Idris
IdrisOP4mo ago
I was thinking of decoding the json response manually but that seems awkward when there is a sdk. Am i missing something?
garyaustin
garyaustin4mo ago
See the error handling tab

Did you find this page helpful?