Merged in fix/warmup-not-throwing (pull request #3179)
fix: warmup threw error * fix: warmup threw error * . Approved-by: Linus Flood
This commit is contained in:
11
apps/scandic-web/netlify/utils/safeTry.ts
Normal file
11
apps/scandic-web/netlify/utils/safeTry.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
export type SafeTryResult<T> = Promise<
|
||||
[T, undefined] | [undefined, Error | unknown]
|
||||
>
|
||||
|
||||
export async function safeTry<T>(func: Promise<T>): SafeTryResult<T> {
|
||||
try {
|
||||
return [await func, undefined] as const
|
||||
} catch (err) {
|
||||
return [undefined, err instanceof Error ? err : (err as unknown)] as const
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user