UNPKG

@stacksjs/error-handling

Version:
1 lines 317 B
import{ErrorHandler}from"./handler";export function rescue(fn,fallback,onError){try{const result=fn();if(result instanceof Promise)return result.catch((error)=>{if(onError)onError(ErrorHandler.handle(error));return fallback});return result}catch(error){if(onError)onError(ErrorHandler.handle(error));return fallback}}