catchbuddy
Version:
Simplify error handling in JavaScript with a lightweight utility that organizes results and errors for both synchronous and asynchronous operations.
2 lines (1 loc) • 398 B
JavaScript
function t(r){if(r instanceof Error)return r;let n=r===null?"null":typeof r,e=String(r);if(n==="object")try{e=JSON.stringify(r)}catch{e=String(r)}return new Error(`An error of type "${n}" was thrown: ${e}`)}async function o(r){try{return[void 0,await r]}catch(n){return[t(n),void 0]}}var s=(r,...n)=>{try{return[void 0,r(...n)]}catch(e){return[t(e),void 0]}};export{o as resolve,s as resolveSync};