postgrest-js
postgrest-js copied to clipboard
Error is an empty object
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
System information
- OS: windows
- Browser: chrome
- Version of postgrest-js: v1.1.1
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
Sorry for my late response.

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.
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 here is a failing test which shows the issue for insert(): https://github.com/jcerjak/postgrest-js/commit/9d8b90dca0dbe5e0095f13a8862ff12d1cad4c18