Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/request / dist / deps / toPrettyError.js
Size: Mime:
"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