Skip to content

Commit

Permalink
fix: populate details on FetchError
Browse files Browse the repository at this point in the history
  • Loading branch information
soedirgo committed Apr 18, 2023
1 parent 320ac92 commit 1e2981f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/PostgrestBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ export default abstract class PostgrestBuilder<Result>
if (!this.shouldThrowOnError) {
res = res.catch((fetchError) => ({
error: {
message: `FetchError: ${fetchError.message}`,
details: '',
message: `${fetchError?.name ?? 'FetchError'}: ${fetchError?.message}`,
details: `${fetchError?.stack ?? ''}`,
hint: '',
code: fetchError.code || '',
code: `${fetchError?.code ?? ''}`,
},
data: null,
count: null,
Expand Down
11 changes: 7 additions & 4 deletions test/transforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,20 +247,23 @@ test('abort signal', async () => {
const ac = new AbortController() as globalThis.AbortController
ac.abort()
const res = await postgrest.from('users').select().abortSignal(ac.signal)
expect(res).toMatchInlineSnapshot(`
expect(res).toMatchInlineSnapshot(
{ error: { details: expect.any(String) } },
`
Object {
"count": null,
"data": null,
"error": Object {
"code": "",
"details": "",
"details": Any<String>,
"hint": "",
"message": "FetchError: The user aborted a request.",
"message": "AbortError: The user aborted a request.",
},
"status": 0,
"statusText": "",
}
`)
`
)
})

// test('geojson', async () => {
Expand Down

0 comments on commit 1e2981f

Please sign in to comment.