Open cryptoseneca opened 1 year ago
This simple, if the response .ok
value is false (only true for values 200-299), the code throws a FunctionsHTTPError
:
This error is gobbling up the error thrown and returns a generic message:
These custom function error classes are opinionated and override the expected error response of the edge function logic. However, the error returned has a context
property that contains what you would expect to receive.
+1
+1
If anyone comes here and just want to show the error, this was my solution: https://supabase.com/docs/guides/functions/quickstart#error-handling
import { FunctionsHttpError } from '@supabase/supabase-js'
const { data, error } = await supabase.functions.invoke('...')
if (error && error instanceof FunctionsHttpError) {
const errorMessage = await error.context.json()
console.log('Function returned an error', errorMessage)
}
Bug report
Describe the bug
When returning responses from Edge Functions, Documentation suggests
new Response('..', {status: 200})
. This works fine as one can see the success message in thedata
var. When returning a Response with a non-200 status code, the message is not available to the client.edge func:
client:
When it is a
200
response,data
will display the message but when it is non-200 (eg400
), theerror
var does not show the message - it only returns a generic message:To Reproduce
Explained above.
Expected behavior
error
to contain whatever message is added to theResponse
object.System information
"@supabase/supabase-js": "^2.20.0"
v16.17.1