lib/util/common.js
function buildErrorObject(params){
  params = params || {};

  //If the userDetail is already set, not building the error object again.
  if(params.err && params.err.userDetail){
    return params;
  }

  var err = params.err || {message: "Unexpected Error"};
  var msg = params.msg || params.err.message || "Unexpected Error";
  var httpCode = params.httpCode || 500;
  //Custom Error Code
  var code = params.code || "FH-MBAAS-ERROR";

  var response = {
    errorFields: {
      userDetail: msg,
      systemDetail: msg + ' - ' + util.inspect(err),
      code: code
    },
    httpCode: httpCode
  };
  if (params.explain) {
    response.errorFields.explain = params.explain;
  }

  return response;
}
function buildErrorObject(params){
  params = params || {};

  //If the userDetail is already set, not building the error object again.
  if(params.err && params.err.userDetail){
    return params;
  }

  var err = params.err || {message: "Unexpected Error"};
  var msg = params.msg || params.err.message || "Unexpected Error";
  var httpCode = params.httpCode || 500;
  //Custom Error Code
  var code = params.code || "FH-MBAAS-ERROR";

  var response = {
    errorFields: {
      userDetail: msg,
      systemDetail: msg + ' - ' + util.inspect(err),
      code: code
    },
    httpCode: httpCode
  };
  if (params.explain) {
    response.errorFields.explain = params.explain;
  }

  return response;
}
function buildErrorObject ( params ) { params = params || { } ; //If the userDetail is already set, not building the error object again. if ( params . err && params . err . userDetail ) { return params ; } var err = params . err || { message : "Unexpected Error" } ; var msg = params . msg || params . err . message || "Unexpected Error" ; var httpCode = params . httpCode || 500 ; //Custom Error Code var code = params . code || "FH-MBAAS-ERROR" ; var response = { errorFields : { userDetail : msg , systemDetail : msg + ' - ' + util . inspect ( err ) , code : code } , httpCode : httpCode } ; if ( params . explain ) { response . errorFields . explain = params . explain ; } return response ; }
First step to creating common error codes.

TODO: Make A Module..
@param err
@param msg
@param code
@returns {{error: string}}
First step to creating common error codes .