modern-errors-process
Version:
`modern-errors` plugin to handle process errors
41 lines (29 loc) • 706 B
JavaScript
import logProcessErrors,{validateOptions}from"log-process-errors";
const getOptions=(options)=>{
validateOptions(options);
return addDefaultOptions(options)
};
const addDefaultOptions=({onError=defaultOnError,...options}={})=>({
...options,
onError
});
const defaultOnError=(error)=>{
console.error(error)
};
const logProcess=({options,ErrorClass})=>{
const onError=customOnError.bind(undefined,{options,ErrorClass});
return logProcessErrors({...options,onError})
};
const customOnError=async(
{options:{onError},ErrorClass},
error,
...args)=>
{
const errorA=ErrorClass.normalize(error);
await onError(errorA,...args)
};
export default{
name:"process",
getOptions,
staticMethods:{logProcess}
};