Skip to content

Commit

Permalink
slightoy nicer query error formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mmkal committed Sep 18, 2024
1 parent d34c374 commit 815fbf9
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/client/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,15 @@ export class QueryError extends Error {
result?: {rows: unknown[]}
}

constructor(message: string, cause: Omit<QueryError['cause'], 'name' | 'message'>) {
super(`[Query ${cause.query.name}]: ${message || cause?.error?.message || cause?.error?.constructor?.name}`, {
cause,
constructor(message: string, params: Omit<QueryError['cause'], 'name' | 'message'>) {
super(`[Query ${params.query.name}]: ${message}`, {
cause: params,
})
this.cause = {...cause, message: cause?.error?.message || '', name: 'QueryErrorCause'}
this.cause = {
name: 'QueryErrorCause',
message: params?.error?.message || params.error?.constructor?.name || 'Query error',
...params,
}
}
}

Expand Down

0 comments on commit 815fbf9

Please sign in to comment.