Skip to content

Commit 1e2981f

Browse files
committed
fix: populate details on FetchError
1 parent 320ac92 commit 1e2981f

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/PostgrestBuilder.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ export default abstract class PostgrestBuilder<Result>
150150
if (!this.shouldThrowOnError) {
151151
res = res.catch((fetchError) => ({
152152
error: {
153-
message: `FetchError: ${fetchError.message}`,
154-
details: '',
153+
message: `${fetchError?.name ?? 'FetchError'}: ${fetchError?.message}`,
154+
details: `${fetchError?.stack ?? ''}`,
155155
hint: '',
156-
code: fetchError.code || '',
156+
code: `${fetchError?.code ?? ''}`,
157157
},
158158
data: null,
159159
count: null,

test/transforms.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,20 +247,23 @@ test('abort signal', async () => {
247247
const ac = new AbortController() as globalThis.AbortController
248248
ac.abort()
249249
const res = await postgrest.from('users').select().abortSignal(ac.signal)
250-
expect(res).toMatchInlineSnapshot(`
250+
expect(res).toMatchInlineSnapshot(
251+
{ error: { details: expect.any(String) } },
252+
`
251253
Object {
252254
"count": null,
253255
"data": null,
254256
"error": Object {
255257
"code": "",
256-
"details": "",
258+
"details": Any<String>,
257259
"hint": "",
258-
"message": "FetchError: The user aborted a request.",
260+
"message": "AbortError: The user aborted a request.",
259261
},
260262
"status": 0,
261263
"statusText": "",
262264
}
263-
`)
265+
`
266+
)
264267
})
265268

266269
// test('geojson', async () => {

0 commit comments

Comments
 (0)