lib/utils.js
function parseResponse(response) {
    var code = response.statusCode;
    var type = code / 100 | 0;
    response.type = type;

    // basics
    switch (type) {
    case 1:
        response.info = type;
        break;
    case 2:
        response.ok = type;
        break;
    case 3:
        // ???
        break;
    case 4:
        response.clientError = type;
        response.error = type;
        response.ErrorClass = errors.HttpStatusError;
        break;
    case 5:
        response.serverError = type;
        response.error = type;
        response.ErrorClass = errors.HttpStatusError;
        break;
    }

    // error classes and sugar
    switch (code) {
    case 201:
        response.created = code;
        break;
    case 202:
        response.accepted = code;
        break;
    case 204:
        response.noContent = code;
        break;
    case 400:
        response.badRequest = code;
        break;
    case 401:
        response.unauthorized = code;
        response.ErrorClass = errors.AuthenticationRequiredError;
        break;
    case 403:
        response.forbidden = code;
        response.ErrorClass = errors.NotPermittedError;
        break;
    case 404:
        response.notFound = code;
        response.ErrorClass = errors.NotFoundError;
        break;
    case 406:
        response.notAcceptable = code;
        break;
    case 500:
        response.internalServerError = code;
        break;
    }

    // using body (and not status code)
    if (response.body && response.body.success === false) {
        if (!response.error) {
            response.error = 4; // assume is client error
            response.ErrorClass = errors.HttpStatusError;
        }
    }

    // null bodies
    if (_.includes([null, undefined, ""], response.body)) {
        if (!response.error) {
            response.error = 5; // assume the server fucked up
            response.ErrorClass = errors.HttpStatusError;
        }
    }

    return response;
}
function parseResponse(response) {
    var code = response.statusCode;
    var type = code / 100 | 0;
    response.type = type;

    // basics
    switch (type) {
    case 1:
        response.info = type;
        break;
    case 2:
        response.ok = type;
        break;
    case 3:
        // ???
        break;
    case 4:
        response.clientError = type;
        response.error = type;
        response.ErrorClass = errors.HttpStatusError;
        break;
    case 5:
        response.serverError = type;
        response.error = type;
        response.ErrorClass = errors.HttpStatusError;
        break;
    }

    // error classes and sugar
    switch (code) {
    case 201:
        response.created = code;
        break;
    case 202:
        response.accepted = code;
        break;
    case 204:
        response.noContent = code;
        break;
    case 400:
        response.badRequest = code;
        break;
    case 401:
        response.unauthorized = code;
        response.ErrorClass = errors.AuthenticationRequiredError;
        break;
    case 403:
        response.forbidden = code;
        response.ErrorClass = errors.NotPermittedError;
        break;
    case 404:
        response.notFound = code;
        response.ErrorClass = errors.NotFoundError;
        break;
    case 406:
        response.notAcceptable = code;
        break;
    case 500:
        response.internalServerError = code;
        break;
    }

    // using body (and not status code)
    if (response.body && response.body.success === false) {
        if (!response.error) {
            response.error = 4; // assume is client error
            response.ErrorClass = errors.HttpStatusError;
        }
    }

    // null bodies
    if (_.includes([null, undefined, ""], response.body)) {
        if (!response.error) {
            response.error = 5; // assume the server fucked up
            response.ErrorClass = errors.HttpStatusError;
        }
    }

    return response;
}
function parseResponse ( response ) { var code = response . statusCode ; var type = code / 100 | 0 ; response . type = type ; // basics switch ( type ) { case 1 : response . info = type ; break ; case 2 : response . ok = type ; break ; case 3 : // ??? break ; case 4 : response . clientError = type ; response . error = type ; response . ErrorClass = errors . HttpStatusError ; break ; case 5 : response . serverError = type ; response . error = type ; response . ErrorClass = errors . HttpStatusError ; break ; } // error classes and sugar switch ( code ) { case 201 : response . created = code ; break ; case 202 : response . accepted = code ; break ; case 204 : response . noContent = code ; break ; case 400 : response . badRequest = code ; break ; case 401 : response . unauthorized = code ; response . ErrorClass = errors . AuthenticationRequiredError ; break ; case 403 : response . forbidden = code ; response . ErrorClass = errors . NotPermittedError ; break ; case 404 : response . notFound = code ; response . ErrorClass = errors . NotFoundError ; break ; case 406 : response . notAcceptable = code ; break ; case 500 : response . internalServerError = code ; break ; } // using body (and not status code) if ( response . body && response . body . success === false ) { if ( ! response . error ) { response . error = 4 ; // assume is client error response . ErrorClass = errors . HttpStatusError ; } } // null bodies if ( _ . includes ( [ null , undefined , "" ] , response . body ) ) { if ( ! response . error ) { response . error = 5 ; // assume the server fucked up response . ErrorClass = errors . HttpStatusError ; } } return response ; }
Add properties to response

@private
@see {@link http://visionmedia.github.io/superagent/#response-properties}

@param {Object} response - as from the `request` module
@return {Object} the originally passed but modified reponse
Add properties to response