🔨defineWrapConfig
Set Panic By Default
By default, when a user trying to unwrap a wrapped function, unwrapit will throw an error no matter in a browser or in Node.js. However, you may want the Node program to exit when an error occurs.
One way is that you can use the {panic: true} option
(await wrap(Promise.reject('error'))).unwrap({panic: true})If you want the program to exit by default, then can set the panic by default
import {defineWrapConfig} from 'unwrapit'
defineWrapConfig({panic: true})Customize Panic Function
Sometimes, you may want to have a central place to handle all the errors, you can set your do this simply by providing your own panic function which conforms to the below signature.
(message: any, opt?: {cause?: any; shouldExit?: boolean; exitCode?: number}) => neverHere's an example
import {defineWrapConfig} from 'unwrapit'
class MyError extends Error {}
function myPanic(message: any): never {
throw new MyError(message)
}
defineWrapConfig({panicFn: myPanic})Last updated