auth-js icon indicating copy to clipboard operation
auth-js copied to clipboard

Error messages not being parsed correctly

Open awalias opened this issue 3 years ago • 1 comments

recently we got a report from usage of supabase-js:

FetchError: invalid json response body at https://fscmlciotnxwjzflqzqs.supabase.co/auth/v1/admin/users reason: Unexpected token < in JSON at position 0

it's suspected that the error in question was either due to a failed request:

{
  "code": 422,
  "msg": "Email address already registered by another user"
}
// POST https://{REF}.supabase.in/auth/v1/admin/users
// HTTP/1.1 422 Unprocessable Entity
// Date: Thu, 26 May 2022 00:46:27 GMT
// Content-Type: application/json
// Content-Length: 69

or

Status
524
MethodPOST
Timestamp1653499427722000
IP Address173.70.226.178
Origin CountryUS
Clientsupabase-js/1.35.3

a 524 is a cloudflare specific error

we should try and reproduce both and make sure we are handling the errors correctly in the client

awalias avatar May 26 '22 15:05 awalias

FetchError: invalid json response body ... can be observed when response.json() is called on a response that is not valid json. Both 1.22.22 and 1.23.0-next.16 do currently not catch this error.

See 1.23.0-next.16 https://github.com/supabase/gotrue-js/blob/67a6575102be9c50763ff5d06fd2ee44b18a69f3/src/lib/fetch.ts#L26-L28

PR #379 will catch this error and reject with an AuthUnknownError.

pixtron avatar Aug 13 '22 14:08 pixtron

This has been fixed. Thank you @pixtron!

hf avatar Dec 30 '22 18:12 hf