mirror of
https://github.com/pockethost/pockethost.git
synced 2025-03-30 15:08:30 +00:00
17 lines
346 B
TypeScript
17 lines
346 B
TypeScript
import { dev } from '$app/environment'
|
|
|
|
export const safeCatch = <TIn extends any[], TOut>(
|
|
name: string,
|
|
cb: (...args: TIn) => Promise<TOut>
|
|
) => {
|
|
return (...args: TIn) => {
|
|
if (dev) {
|
|
console.log(`${name}`)
|
|
}
|
|
return cb(...args).catch((e: any) => {
|
|
console.error(`${name} failed: ${e}`)
|
|
throw e
|
|
})
|
|
}
|
|
}
|