UNPKG

error-message-utils

Version:

The error-message-utils package simplifies error management in your web applications and RESTful APIs. It ensures consistent and scalable handling of error messages, saving you time and effort. Moreover, it gives you the ability to assign custom error cod

1 lines 652 B
const CODE_WRAPPER={prefix:"{(",suffix:")}"},DEFAULT_MESSAGE="The error message could not be extracted, check the logs for more information.",DEFAULT_CODE=-1,wrapCode=e=>`${CODE_WRAPPER.prefix}${e??-1}${CODE_WRAPPER.suffix}`,__isEncodedError=e=>new RegExp(`${CODE_WRAPPER.prefix}.+${CODE_WRAPPER.suffix}$`).test(e),__isNumeric=e=>!Number.isNaN(Number.parseFloat(e)),unwrapCode=e=>{if(__isEncodedError(e)){const r=e.lastIndexOf(CODE_WRAPPER.prefix),E=e.substring(r+2,e.lastIndexOf(CODE_WRAPPER.suffix));return{code:__isNumeric(E)?Number(E):E,startsAt:r}}return{code:-1,startsAt:-1}};export{CODE_WRAPPER,DEFAULT_MESSAGE,DEFAULT_CODE,wrapCode,unwrapCode};