Skip to content

Commit 6c2e676

Browse files
darorasoedirgo
authored andcommitted
feat: support throwing errors by default
1 parent 9e60bc3 commit 6c2e676

File tree

5 files changed

+19
-7
lines changed

5 files changed

+19
-7
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
},
3939
"dependencies": {
4040
"@supabase/gotrue-js": "^1.22.3",
41-
"@supabase/postgrest-js": "^0.36.2",
41+
"@supabase/postgrest-js": "^0.37.0",
4242
"@supabase/realtime-js": "^1.3.6",
4343
"@supabase/storage-js": "^1.6.4"
4444
},

src/SupabaseClient.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { SupabaseAuthClient } from './lib/SupabaseAuthClient'
55
import { SupabaseQueryBuilder } from './lib/SupabaseQueryBuilder'
66
import { SupabaseStorageClient } from '@supabase/storage-js'
77
import { PostgrestClient } from '@supabase/postgrest-js'
8-
import { AuthChangeEvent, Session, Subscription } from '@supabase/gotrue-js'
8+
import { AuthChangeEvent } from '@supabase/gotrue-js'
99
import { RealtimeClient, RealtimeSubscription, RealtimeClientOptions } from '@supabase/realtime-js'
1010

1111
const DEFAULT_OPTIONS = {
@@ -37,6 +37,8 @@ export default class SupabaseClient {
3737
protected multiTab: boolean
3838
protected fetch?: Fetch
3939
protected changedAccessToken: string | undefined
40+
protected shouldThrowOnError: boolean
41+
4042
protected headers: {
4143
[key: string]: string
4244
}
@@ -73,6 +75,7 @@ export default class SupabaseClient {
7375
this.multiTab = settings.multiTab
7476
this.fetch = settings.fetch
7577
this.headers = { ...DEFAULT_HEADERS, ...options?.headers }
78+
this.shouldThrowOnError = settings.shouldThrowOnError || false
7679

7780
this.auth = this._initSupabaseAuthClient(settings)
7881
this.realtime = this._initRealtimeClient({ headers: this.headers, ...settings.realtime })
@@ -106,6 +109,7 @@ export default class SupabaseClient {
106109
realtime: this.realtime,
107110
table,
108111
fetch: this.fetch,
112+
shouldThrowOnError: this.shouldThrowOnError,
109113
})
110114
}
111115

@@ -235,6 +239,7 @@ export default class SupabaseClient {
235239
headers: this._getAuthHeaders(),
236240
schema: this.schema,
237241
fetch: this.fetch,
242+
throwOnError: this.shouldThrowOnError,
238243
})
239244
}
240245

src/lib/SupabaseQueryBuilder.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@ export class SupabaseQueryBuilder<T> extends PostgrestQueryBuilder<T> {
1818
realtime,
1919
table,
2020
fetch,
21+
shouldThrowOnError,
2122
}: {
2223
headers?: GenericObject
2324
schema: string
2425
realtime: RealtimeClient
2526
table: string
2627
fetch?: Fetch
28+
shouldThrowOnError?: boolean
2729
}
2830
) {
29-
super(url, { headers, schema, fetch })
31+
super(url, { headers, schema, fetch, shouldThrowOnError })
3032

3133
this._realtime = realtime
3234
this._headers = headers

src/lib/types.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { RealtimeClientOptions } from '@supabase/realtime-js'
33

44
type GoTrueClientOptions = ConstructorParameters<typeof GoTrueClient>[0]
55

6-
export interface SupabaseAuthClientOptions extends GoTrueClientOptions {}
6+
export interface SupabaseAuthClientOptions extends GoTrueClientOptions { }
77

88
export type GenericObject = { [key: string]: string }
99

@@ -44,6 +44,11 @@ export type SupabaseClientOptions = {
4444
* A custom `fetch` implementation.
4545
*/
4646
fetch?: Fetch
47+
48+
/**
49+
* Throw errors, instead of returning them.
50+
*/
51+
shouldThrowOnError?: boolean
4752
}
4853

4954
export type SupabaseRealtimePayload<T> = {

0 commit comments

Comments
 (0)