Skip to content

Commit

Permalink
Make sure we catch sync errors when handling sync driver results asyn…
Browse files Browse the repository at this point in the history
…chronously
  • Loading branch information
benmerckx committed Sep 11, 2024
1 parent a1bcef3 commit 6f0e8cc
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/core/Query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Executable<Result, Meta extends QueryMeta>
}

// biome-ignore lint/suspicious/noThenProperty:
then<TResult1 = Array<Result>, TResult2 = never>(
async then<TResult1 = Array<Result>, TResult2 = never>(
onfulfilled?:
| ((value: Array<Result>) => TResult1 | PromiseLike<TResult1>)
| undefined
Expand All @@ -54,8 +54,12 @@ class Executable<Result, Meta extends QueryMeta>
| undefined
| null
): Promise<TResult1 | TResult2> {
const result = this.#execute()
return Promise.resolve(result).then(onfulfilled, onrejected)
try {
const result = await this.#execute()
return onfulfilled ? onfulfilled(result) : result
} catch (error) {
return onrejected ? onrejected(error) : Promise.reject(error)
}
}

catch<TResult = never>(
Expand Down

0 comments on commit 6f0e8cc

Please sign in to comment.