Repository URL to install this package:
|
Version:
7.1.2 ▾
|
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* @todo rewrite this, has side effects
* @description attempt to use better and human-friendly error messages
*/
function toPrettyError(obj) {
let prettyError;
const objAsAny = obj;
const bodyAsError = objAsAny.body;
const bodyAsArray = objAsAny.body;
if (typeof bodyAsError === 'object' &&
typeof bodyAsError.message === 'string') {
prettyError = new Error(bodyAsError.message);
}
else if (!Array.isArray(objAsAny.body) &&
// attempt to utilize Stripe-inspired error messages
typeof bodyAsArray.error === 'object') {
const bodyError = bodyAsArray.error;
if (bodyError.message) {
prettyError = new Error(bodyError.message);
}
if (bodyError.stack) {
prettyError.stack = bodyError.stack;
}
if (bodyError.code) {
prettyError.code = bodyError.code;
}
if (bodyError.param) {
prettyError.param = bodyError.param;
}
}
return prettyError;
}
exports.toPrettyError = toPrettyError;
//# sourceMappingURL=toPrettyError.js.map