Skip to content

Commit

Permalink
feat: support throwing errors by default
Browse files Browse the repository at this point in the history
  • Loading branch information
darora authored and soedirgo committed Mar 7, 2022
1 parent 9e60bc3 commit 6c2e676
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -38,7 +38,7 @@
},
"dependencies": {
"@supabase/gotrue-js": "^1.22.3",
"@supabase/postgrest-js": "^0.36.2",
"@supabase/postgrest-js": "^0.37.0",
"@supabase/realtime-js": "^1.3.6",
"@supabase/storage-js": "^1.6.4"
},
Expand Down
7 changes: 6 additions & 1 deletion src/SupabaseClient.ts
Expand Up @@ -5,7 +5,7 @@ import { SupabaseAuthClient } from './lib/SupabaseAuthClient'
import { SupabaseQueryBuilder } from './lib/SupabaseQueryBuilder'
import { SupabaseStorageClient } from '@supabase/storage-js'
import { PostgrestClient } from '@supabase/postgrest-js'
import { AuthChangeEvent, Session, Subscription } from '@supabase/gotrue-js'
import { AuthChangeEvent } from '@supabase/gotrue-js'
import { RealtimeClient, RealtimeSubscription, RealtimeClientOptions } from '@supabase/realtime-js'

const DEFAULT_OPTIONS = {
Expand Down Expand Up @@ -37,6 +37,8 @@ export default class SupabaseClient {
protected multiTab: boolean
protected fetch?: Fetch
protected changedAccessToken: string | undefined
protected shouldThrowOnError: boolean

protected headers: {
[key: string]: string
}
Expand Down Expand Up @@ -73,6 +75,7 @@ export default class SupabaseClient {
this.multiTab = settings.multiTab
this.fetch = settings.fetch
this.headers = { ...DEFAULT_HEADERS, ...options?.headers }
this.shouldThrowOnError = settings.shouldThrowOnError || false

this.auth = this._initSupabaseAuthClient(settings)
this.realtime = this._initRealtimeClient({ headers: this.headers, ...settings.realtime })
Expand Down Expand Up @@ -106,6 +109,7 @@ export default class SupabaseClient {
realtime: this.realtime,
table,
fetch: this.fetch,
shouldThrowOnError: this.shouldThrowOnError,
})
}

Expand Down Expand Up @@ -235,6 +239,7 @@ export default class SupabaseClient {
headers: this._getAuthHeaders(),
schema: this.schema,
fetch: this.fetch,
throwOnError: this.shouldThrowOnError,
})
}

Expand Down
4 changes: 3 additions & 1 deletion src/lib/SupabaseQueryBuilder.ts
Expand Up @@ -18,15 +18,17 @@ export class SupabaseQueryBuilder<T> extends PostgrestQueryBuilder<T> {
realtime,
table,
fetch,
shouldThrowOnError,
}: {
headers?: GenericObject
schema: string
realtime: RealtimeClient
table: string
fetch?: Fetch
shouldThrowOnError?: boolean
}
) {
super(url, { headers, schema, fetch })
super(url, { headers, schema, fetch, shouldThrowOnError })

this._realtime = realtime
this._headers = headers
Expand Down
7 changes: 6 additions & 1 deletion src/lib/types.ts
Expand Up @@ -3,7 +3,7 @@ import { RealtimeClientOptions } from '@supabase/realtime-js'

type GoTrueClientOptions = ConstructorParameters<typeof GoTrueClient>[0]

export interface SupabaseAuthClientOptions extends GoTrueClientOptions {}
export interface SupabaseAuthClientOptions extends GoTrueClientOptions { }

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

Expand Down Expand Up @@ -44,6 +44,11 @@ export type SupabaseClientOptions = {
* A custom `fetch` implementation.
*/
fetch?: Fetch

/**
* Throw errors, instead of returning them.
*/
shouldThrowOnError?: boolean
}

export type SupabaseRealtimePayload<T> = {
Expand Down

0 comments on commit 6c2e676

Please sign in to comment.