Repository URL to install this package:
|
Version:
5.3.0 ▾
|
/**
* @todo rewrite this, has side effects
*/
export function toPrettyError(obj: Error | Response) {
// attempt to use better and human-friendly error messages
if (typeof obj.body === 'object' && typeof obj.body.message === 'string') {
obj.prettyError = new Error(obj.body.message)
} else if (
!Array.isArray(obj.body) &&
// attempt to utilize Stripe-inspired error messages
typeof obj.body.error === 'object'
) {
if (obj.body.error.message) {
obj.prettyError = new Error(obj.body.error.message)
}
if (obj.body.error.stack) {
obj.prettyError.stack = obj.body.error.stack
}
if (obj.body.error.code) {
obj.prettyError.code = obj.body.error.code
}
if (obj.body.error.param) {
obj.prettyError.param = obj.body.error.param
}
}
}