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

Error is an empty object

Open alexkreidler opened this issue 2 years ago • 4 comments

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

  • OS: windows
  • Browser: chrome
  • Version of postgrest-js: v1.1.1

alexkreidler avatar Dec 17 '22 23:12 alexkreidler

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

soedirgo avatar Jan 06 '23 06:01 soedirgo

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.

alexkreidler avatar Apr 09 '23 04:04 alexkreidler

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.

soedirgo avatar Apr 18 '23 13:04 soedirgo

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

jcerjak avatar Dec 14 '23 19:12 jcerjak