Skip to content

Commit

Permalink
chore: stricter typing
Browse files Browse the repository at this point in the history
  • Loading branch information
soedirgo committed Jan 15, 2024
1 parent acc0d42 commit 0679c73
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
19 changes: 13 additions & 6 deletions src/PostgrestError.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
class PostgrestError extends Error {
constructor(details: { message?: string } & Record<string, unknown>) {
super(details.message ?? 'Unknown Postgrest error')
Object.assign(this, details)
import type { PostgrestError as IPostgrestError } from './types'

export default class PostgrestError extends Error implements IPostgrestError {
details: string
hint: string
code: string

constructor(context: IPostgrestError) {
super(context.message)
this.name = 'PostgrestError'
this.details = context.details
this.hint = context.hint
this.code = context.code
}
}

export default PostgrestError
2 changes: 1 addition & 1 deletion test/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ test('throwOnError throws errors instead of returning them', async () => {

test('throwOnError throws errors which include stack', async () => {
try {
const res = await postgrest.from('does_not_exist').select().throwOnError()
await postgrest.from('does_not_exist').select().throwOnError()
} catch (err) {
expect(err instanceof Error).toBe(true)
expect((err as Error).stack).not.toBeUndefined()
Expand Down

0 comments on commit 0679c73

Please sign in to comment.