{"size": 950, "ext": "js", "max_stars_repo_path": "backend/utils/ResponseWrapper.js", "max_stars_repo_name": "Piyush-Use-Personal/MERN-Activity", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "backend/utils/ResponseWrapper.js", "max_issues_repo_name": "Piyush-Use-Personal/MERN-Activity", "max_issues_repo_issues_event_min_datetime": "2021-04-19T06:57:13.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-19T06:57:13.000Z", "max_forks_repo_path": "backend/utils/ResponseWrapper.js", "max_forks_repo_name": "Piyush-Use-Personal/MERN-Activity", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 24.358974359, "max_line_length": 60, "alphanum_fraction": 0.6621052632}
/**
 * Created by Piyush on 26/9/2020.
*/
var messages = require('../static/StatusMessages');
var error_pointer = 'codes'
function SuccessResponse (code, res, responseObj, message) {
    var response = {};
    response.code = code;
    response.result = responseObj;
    if (code !== 200) {
      response.message = messages[error_pointer][code];
    } else {
      response.message = message;
    }
    res.status(200).send(response);
  }

function FailedResponse(err, res){
  var err_codes = Object.keys(messages[error_pointer]);
  if (err_codes.indexOf(err.toString()) !== -1) {
    SuccessResponse(err, res, {})
  } else {
    InternalServerResponse(err, res);
  }

};

function InternalServerResponse(error, res){
    res.status(500).send({'error' : error.message});
}
  
  /// --- Exports
  module.exports = {
    SuccessResponse: SuccessResponse,
    InternalServerResponse : InternalServerResponse,
    FailedResponse: FailedResponse
  };
  
