supabase / postgrest-js

Isomorphic JavaScript client for PostgREST.
https://supabase.com
MIT License
1.04k stars 133 forks source link

Error is an empty object #381

Open alexkreidler opened 1 year ago

alexkreidler commented 1 year ago

Bug report

I'm making a request like this:

const res = await postgrest.from('surveys').select('*').eq('id', 'abc')
console.log(res)

The HTTP request to the relevant URL (localhost:5001/surveys?id=eq.abc&select=*) returns a 404 status code and this JSON:

{"code":"22P02","details":null,"hint":null,"message":"invalid input syntax for type uuid: \"abc\""}

Describe the bug

When I print res, res.error is an empty object, instead of the expected object containing the JSON response data.

Screenshots

image

System information

soedirgo commented 1 year ago

The screenshot seems to say that error contains something - can you click the dropdown button there?

Also wrt the invalid input syntax error, can you make sure that you're querying the right table and that id has the type you expect? See also: https://github.com/supabase/postgrest-js/issues/376#issuecomment-1344518310

alexkreidler commented 1 year ago

Sorry for my late response.

image

As you can see, that's simply Chrome DevTools' representation of an empty object. And yes I am querying the right table, but purposefully with a bad string id "abc" for the reproducibility of this bug. If you try writing any error-inducing code with library that results in a PostgREST-level error, unfortunately the library will not return it to the user. This is a pretty critical issue for me.

soedirgo commented 1 year ago

Ah got it, so the issue is the error from PostgREST isn't being populated on the error field - the invalid UUID format in the example is intentional. Can you see if it helps to update the library version? If not, can you put up a repo so I can reproduce this? We have tests on the error response so it's odd that this happens.

jcerjak commented 9 months ago

@soedirgo here is a failing test which shows the issue for insert(): https://github.com/jcerjak/postgrest-js/commit/9d8b90dca0dbe5e0095f13a8862ff12d1cad4c18