lib/registry-client-v2.js
function _getRegistryErrMessage(body) {
    if (!body) {
        return null;
    }
    var obj = body;
    if (typeof (obj) === 'string' && obj.length <= MAX_REGISTRY_ERROR_LENGTH) {
        try {
            obj = JSON.parse(obj);
        } catch (ex) {
            // Just return the error as a string.
            return obj;
        }
    }
    if (typeof (obj) !== 'object' || !obj.hasOwnProperty('errors')) {
        return null;
    }
    if (!Array.isArray(obj.errors)) {
        return null;
    }
    // Example obj:
    // {
    //     "errors": [
    //         {
    //             "code": "MANIFEST_INVALID",
    //             "message": "manifest invalid",
    //             "detail": {}
    //         }
    //     ]
    // }
    if (obj.errors.length === 1) {
        return obj.errors[0].message;
    } else {
        return obj.errors.map(function (o) {
            return o.message;
        }).join(', ');
    }
}
function _getRegistryErrMessage(body) {
    if (!body) {
        return null;
    }
    var obj = body;
    if (typeof (obj) === 'string' && obj.length <= MAX_REGISTRY_ERROR_LENGTH) {
        try {
            obj = JSON.parse(obj);
        } catch (ex) {
            // Just return the error as a string.
            return obj;
        }
    }
    if (typeof (obj) !== 'object' || !obj.hasOwnProperty('errors')) {
        return null;
    }
    if (!Array.isArray(obj.errors)) {
        return null;
    }
    // Example obj:
    // {
    //     "errors": [
    //         {
    //             "code": "MANIFEST_INVALID",
    //             "message": "manifest invalid",
    //             "detail": {}
    //         }
    //     ]
    // }
    if (obj.errors.length === 1) {
        return obj.errors[0].message;
    } else {
        return obj.errors.map(function (o) {
            return o.message;
        }).join(', ');
    }
}
function _getRegistryErrMessage ( body ) { if ( ! body ) { return null ; } var obj = body ; if ( typeof ( obj ) === 'string' && obj . length <= MAX_REGISTRY_ERROR_LENGTH ) { try { obj = JSON . parse ( obj ) ; } catch ( ex ) { // Just return the error as a string. return obj ; } } if ( typeof ( obj ) !== 'object' || ! obj . hasOwnProperty ( 'errors' ) ) { return null ; } if ( ! Array . isArray ( obj . errors ) ) { return null ; } // Example obj: // { //     "errors": [ //         { //             "code": "MANIFEST_INVALID", //             "message": "manifest invalid", //             "detail": {} //         } //     ] // } if ( obj . errors . length === 1 ) { return obj . errors [ 0 ] . message ; } else { return obj . errors . map ( function ( o ) { return o . message ; } ) . join ( ', ' ) ; } }
Special handling of JSON body errors from the registry server.

POST/PUT endpoints can return an error in the body of the response.
We want to check for that and get the error body message and return it.

Usage:
var regErr = _getRegistryErrMessage(body));
Special handling of JSON body errors from the registry server .