lib/mbaasRequest/mbaasRequest.js
function responseHandler(params, cb) {

  return function handleResponse(err, httpResponse, body) {
    body = body || "{}";
    httpResponse = httpResponse || {};

    //The response should be JSON. If it is a string, then the response should be parsed.
    if (_.isString(body)) {
      try {
        body = JSON.parse(body);
      } catch (e) {
        log.logger.error("FH-MBAAS-CLIENT: Invalid Response Body ", {body: body});
      }
    }

    log.logger.debug("FH-MBAAS-CLIENT:  Request Finish ", {
      err: err,
      httpResponse: httpResponse.statusCode,
      body: body
    });

    // provide defaults
    if (httpResponse && httpResponse.statusCode >= 400) {
      err = err || {};
      err.httpCode = httpResponse.statusCode;
      err.message = "Unexpected Status Code " + httpResponse.statusCode;
    }

    //There is a specific error message if an environment is unreachable
    if (httpResponse && httpResponse.statusCode === 503) {
      err = {
        httpCode: 503,
        message: CONSTANTS.ERROR_MESSAGES.ENVIRONMENT_UNREACHABLE.replace('{{ENVLABEL}}', params.envLabel || "")
      };
    }

    // MbaaS unavailable
    if (err && err.code !== undefined && (err.code === "ENOTFOUND" || err.code === "ETIMEDOUT")) {
      err = {
        httpCode: httpResponse.statusCode || 500,
        message: "MBaaS environment is not reachable. Please make the environment available or delete it. Environment Label - " + params.envLabel || ""
      };
    }

    if (err) {
      cb(err || body || "Unexpected Status Code " + httpResponse.statusCode);
    } else {
      cb(undefined, body);
    }
  };
}
function responseHandler(params, cb) {

  return function handleResponse(err, httpResponse, body) {
    body = body || "{}";
    httpResponse = httpResponse || {};

    //The response should be JSON. If it is a string, then the response should be parsed.
    if (_.isString(body)) {
      try {
        body = JSON.parse(body);
      } catch (e) {
        log.logger.error("FH-MBAAS-CLIENT: Invalid Response Body ", {body: body});
      }
    }

    log.logger.debug("FH-MBAAS-CLIENT:  Request Finish ", {
      err: err,
      httpResponse: httpResponse.statusCode,
      body: body
    });

    // provide defaults
    if (httpResponse && httpResponse.statusCode >= 400) {
      err = err || {};
      err.httpCode = httpResponse.statusCode;
      err.message = "Unexpected Status Code " + httpResponse.statusCode;
    }

    //There is a specific error message if an environment is unreachable
    if (httpResponse && httpResponse.statusCode === 503) {
      err = {
        httpCode: 503,
        message: CONSTANTS.ERROR_MESSAGES.ENVIRONMENT_UNREACHABLE.replace('{{ENVLABEL}}', params.envLabel || "")
      };
    }

    // MbaaS unavailable
    if (err && err.code !== undefined && (err.code === "ENOTFOUND" || err.code === "ETIMEDOUT")) {
      err = {
        httpCode: httpResponse.statusCode || 500,
        message: "MBaaS environment is not reachable. Please make the environment available or delete it. Environment Label - " + params.envLabel || ""
      };
    }

    if (err) {
      cb(err || body || "Unexpected Status Code " + httpResponse.statusCode);
    } else {
      cb(undefined, body);
    }
  };
}
function responseHandler ( params , cb ) { return function handleResponse ( err , httpResponse , body ) { body = body || "{}" ; httpResponse = httpResponse || { } ; //The response should be JSON. If it is a string, then the response should be parsed. if ( _ . isString ( body ) ) { try { body = JSON . parse ( body ) ; } catch ( e ) { log . logger . error ( "FH-MBAAS-CLIENT: Invalid Response Body " , { body : body } ) ; } } log . logger . debug ( "FH-MBAAS-CLIENT:  Request Finish " , { err : err , httpResponse : httpResponse . statusCode , body : body } ) ; // provide defaults if ( httpResponse && httpResponse . statusCode >= 400 ) { err = err || { } ; err . httpCode = httpResponse . statusCode ; err . message = "Unexpected Status Code " + httpResponse . statusCode ; } //There is a specific error message if an environment is unreachable if ( httpResponse && httpResponse . statusCode === 503 ) { err = { httpCode : 503 , message : CONSTANTS . ERROR_MESSAGES . ENVIRONMENT_UNREACHABLE . replace ( '{{ENVLABEL}}' , params . envLabel || "" ) } ; } // MbaaS unavailable if ( err && err . code !== undefined && ( err . code === "ENOTFOUND" || err . code === "ETIMEDOUT" ) ) { err = { httpCode : httpResponse . statusCode || 500 , message : "MBaaS environment is not reachable. Please make the environment available or delete it. Environment Label - " + params . envLabel || "" } ; } if ( err ) { cb ( err || body || "Unexpected Status Code " + httpResponse . statusCode ) ; } else { cb ( undefined , body ) ; } } ; }
Create a response handler from a request to the MBaaS.
@param params
@param cb
@returns {handleResponse}
Create a response handler from a request to the MBaaS .