Skip to content

Commit 61e69a4

Browse files
committed
feat: remove client-level throwOnError
1 parent 5614a46 commit 61e69a4

File tree

5 files changed

+44
-87
lines changed

5 files changed

+44
-87
lines changed

src/PostgrestBuilder.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default abstract class PostgrestBuilder<Result>
1010
protected headers: Record<string, string>
1111
protected schema?: string
1212
protected body?: unknown
13-
protected shouldThrowOnError: boolean
13+
protected shouldThrowOnError = false
1414
protected signal?: AbortSignal
1515
protected fetch: Fetch
1616
protected allowEmpty: boolean
@@ -39,11 +39,9 @@ export default abstract class PostgrestBuilder<Result>
3939
* throwing the error instead of returning it as part of a successful response.
4040
*
4141
* {@link https://github.com/supabase/supabase-js/issues/92}
42-
*
43-
* @deprecated Use `throwOnError` in the `PostgrestClient` constructor instead.
4442
*/
45-
throwOnError(throwOnError?: boolean): this {
46-
this.shouldThrowOnError = throwOnError ?? true
43+
throwOnError(): this {
44+
this.shouldThrowOnError = true
4745
return this
4846
}
4947

src/PostgrestClient.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ export default class PostgrestClient<
1717
headers: Record<string, string>
1818
schema?: SchemaName
1919
fetch?: Fetch
20-
shouldThrowOnError: boolean
2120

21+
// TODO: Add back shouldThrowOnError once we figure out the typings
2222
/**
2323
* Creates a PostgREST client.
2424
*
@@ -32,19 +32,16 @@ export default class PostgrestClient<
3232
headers = {},
3333
schema,
3434
fetch,
35-
throwOnError = false,
3635
}: {
3736
headers?: Record<string, string>
3837
schema?: SchemaName
3938
fetch?: Fetch
40-
throwOnError?: boolean
4139
} = {}
4240
) {
4341
this.url = url
4442
this.headers = { ...DEFAULT_HEADERS, ...headers }
4543
this.schema = schema
4644
this.fetch = fetch
47-
this.shouldThrowOnError = throwOnError
4845
}
4946

5047
/**
@@ -73,7 +70,6 @@ export default class PostgrestClient<
7370
headers: { ...this.headers },
7471
schema: this.schema,
7572
fetch: this.fetch,
76-
shouldThrowOnError: this.shouldThrowOnError,
7773
})
7874
}
7975

@@ -132,7 +128,6 @@ export default class PostgrestClient<
132128
schema: this.schema,
133129
body,
134130
fetch: this.fetch,
135-
shouldThrowOnError: this.shouldThrowOnError,
136131
allowEmpty: false,
137132
} as unknown as PostgrestBuilder<Function_['Returns']>)
138133
}

src/PostgrestQueryBuilder.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export default class PostgrestQueryBuilder<Table extends GenericTable> {
77
url: URL
88
headers: Record<string, string>
99
schema?: string
10-
shouldThrowOnError: boolean
1110
signal?: AbortSignal
1211
fetch?: Fetch
1312

@@ -17,19 +16,16 @@ export default class PostgrestQueryBuilder<Table extends GenericTable> {
1716
headers = {},
1817
schema,
1918
fetch,
20-
shouldThrowOnError,
2119
}: {
2220
headers?: Record<string, string>
2321
schema?: string
2422
fetch?: Fetch
25-
shouldThrowOnError: boolean
2623
}
2724
) {
2825
this.url = url
2926
this.headers = headers
3027
this.schema = schema
3128
this.fetch = fetch
32-
this.shouldThrowOnError = shouldThrowOnError
3329
}
3430

3531
/**
@@ -78,7 +74,6 @@ export default class PostgrestQueryBuilder<Table extends GenericTable> {
7874
headers: this.headers,
7975
schema: this.schema,
8076
fetch: this.fetch,
81-
shouldThrowOnError: this.shouldThrowOnError,
8277
allowEmpty: false,
8378
} as unknown as PostgrestBuilder<Result>)
8479
}
@@ -124,7 +119,6 @@ export default class PostgrestQueryBuilder<Table extends GenericTable> {
124119
schema: this.schema,
125120
body,
126121
fetch: this.fetch,
127-
shouldThrowOnError: this.shouldThrowOnError,
128122
allowEmpty: false,
129123
} as unknown as PostgrestBuilder<undefined>)
130124
}
@@ -171,7 +165,6 @@ export default class PostgrestQueryBuilder<Table extends GenericTable> {
171165
schema: this.schema,
172166
body,
173167
fetch: this.fetch,
174-
shouldThrowOnError: this.shouldThrowOnError,
175168
allowEmpty: false,
176169
} as unknown as PostgrestBuilder<undefined>)
177170
}
@@ -208,7 +201,6 @@ export default class PostgrestQueryBuilder<Table extends GenericTable> {
208201
schema: this.schema,
209202
body,
210203
fetch: this.fetch,
211-
shouldThrowOnError: this.shouldThrowOnError,
212204
allowEmpty: false,
213205
} as unknown as PostgrestBuilder<undefined>)
214206
}
@@ -239,7 +231,6 @@ export default class PostgrestQueryBuilder<Table extends GenericTable> {
239231
headers: this.headers,
240232
schema: this.schema,
241233
fetch: this.fetch,
242-
shouldThrowOnError: this.shouldThrowOnError,
243234
allowEmpty: false,
244235
} as unknown as PostgrestBuilder<undefined>)
245236
}

test/__snapshots__/index.test.ts.snap

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,33 +1393,6 @@ Object {
13931393
}
13941394
`;
13951395
1396-
exports[`throwOnError can be disabled per call 1`] = `
1397-
Object {
1398-
"code": "42P01",
1399-
"details": null,
1400-
"hint": null,
1401-
"message": "relation \\"public.missing_table\\" does not exist",
1402-
}
1403-
`;
1404-
1405-
exports[`throwOnError setting at the client level - query 1`] = `
1406-
Object {
1407-
"code": "42P01",
1408-
"details": null,
1409-
"hint": null,
1410-
"message": "relation \\"public.missing_table\\" does not exist",
1411-
}
1412-
`;
1413-
1414-
exports[`throwOnError setting at the client level - rpc 1`] = `
1415-
Object {
1416-
"code": "PGRST202",
1417-
"details": null,
1418-
"hint": "If a new function was created in the database with this name and parameters, try reloading the schema cache.",
1419-
"message": "Could not find the public.missing_fn() function or the public.missing_fn function with a single unnamed json or jsonb parameter in the schema cache",
1420-
}
1421-
`;
1422-
14231396
exports[`throwOnError throws errors instead of returning them 1`] = `
14241397
Object {
14251398
"code": "42P01",

test/basic.ts

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -173,45 +173,45 @@ test('throwOnError throws errors instead of returning them', async () => {
173173
expect(isErrorCaught).toBe(true)
174174
})
175175

176-
test('throwOnError setting at the client level - query', async () => {
177-
let isErrorCaught = false
178-
const postgrest_ = new PostgrestClient<Database>(REST_URL, { throwOnError: true })
179-
180-
try {
181-
// @ts-expect-error missing table
182-
await postgrest_.from('missing_table').select()
183-
} catch (error) {
184-
expect(error).toMatchSnapshot()
185-
isErrorCaught = true
186-
}
187-
188-
expect(isErrorCaught).toBe(true)
189-
})
190-
191-
test('throwOnError setting at the client level - rpc', async () => {
192-
let isErrorCaught = false
193-
const postgrest_ = new PostgrestClient<Database>(REST_URL, { throwOnError: true })
194-
195-
try {
196-
// @ts-expect-error missing function
197-
await postgrest_.rpc('missing_fn').select()
198-
} catch (error) {
199-
expect(error).toMatchSnapshot()
200-
isErrorCaught = true
201-
}
202-
203-
expect(isErrorCaught).toBe(true)
204-
})
205-
206-
test('throwOnError can be disabled per call', async () => {
207-
let isErrorCaught = false
208-
const postgrest_ = new PostgrestClient<Database>(REST_URL, { throwOnError: true })
209-
// @ts-expect-error missing table
210-
const { error } = await postgrest_.from('missing_table').select().throwOnError(false)
211-
212-
expect(error).toMatchSnapshot()
213-
expect(isErrorCaught).toBe(false)
214-
})
176+
// test('throwOnError setting at the client level - query', async () => {
177+
// let isErrorCaught = false
178+
// const postgrest_ = new PostgrestClient<Database>(REST_URL, { throwOnError: true })
179+
180+
// try {
181+
// // @ts-expect-error missing table
182+
// await postgrest_.from('missing_table').select()
183+
// } catch (error) {
184+
// expect(error).toMatchSnapshot()
185+
// isErrorCaught = true
186+
// }
187+
188+
// expect(isErrorCaught).toBe(true)
189+
// })
190+
191+
// test('throwOnError setting at the client level - rpc', async () => {
192+
// let isErrorCaught = false
193+
// const postgrest_ = new PostgrestClient<Database>(REST_URL, { throwOnError: true })
194+
195+
// try {
196+
// // @ts-expect-error missing function
197+
// await postgrest_.rpc('missing_fn').select()
198+
// } catch (error) {
199+
// expect(error).toMatchSnapshot()
200+
// isErrorCaught = true
201+
// }
202+
203+
// expect(isErrorCaught).toBe(true)
204+
// })
205+
206+
// test('throwOnError can be disabled per call', async () => {
207+
// let isErrorCaught = false
208+
// const postgrest_ = new PostgrestClient<Database>(REST_URL, { throwOnError: true })
209+
// // @ts-expect-error missing table
210+
// const { error } = await postgrest_.from('missing_table').select().throwOnError(false)
211+
212+
// expect(error).toMatchSnapshot()
213+
// expect(isErrorCaught).toBe(false)
214+
// })
215215

216216
test('connection error w/o throwing', async () => {
217217
const postgrest = new PostgrestClient<Database>('http://foo.invalid')
@@ -246,7 +246,7 @@ test('maybeSingle w/ throwOnError', async () => {
246246
.from('messages')
247247
.select()
248248
.eq('message', 'i do not exist')
249-
.throwOnError(true)
249+
.throwOnError()
250250
.maybeSingle()
251251
.then(undefined, () => {
252252
passes = false

0 commit comments

Comments
 (0)