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) • 527 B
JavaScript
async function s(t){try{return[void 0,await t]}catch(e){if(e instanceof Error)return[e,void 0];let r=e===null?"null":typeof e,n=String(e);return r==="object"&&(n=JSON.stringify(e)),[new Error(`An error of type "${r}" was thrown: ${n}`),void 0]}}var u=(t,...e)=>{try{return[void 0,t(...e)]}catch(r){if(r instanceof Error)return[r,void 0];let n=r===null?"null":typeof r,o=String(r);return n==="object"&&(o=JSON.stringify(r)),[new Error(`An error of type "${n}" was thrown: ${o}`),void 0]}};export{s as resolve,u as resolveSync};