Name

sn_mab_api.ErrorHandler

Description

No description available

Script

var ErrorHandler = Class.create();
ErrorHandler.prototype = {
  initialize: function() {
  },

  type: 'ErrorHandler',

  throwBadRequestError: function (message) {
  	var error = new Error(message);
  	error.name = 'BadRequestError';
  	error.fBadRequest = true;
  	throw error;
  },

  throwBadConfigError: function (message) {
  	var error = new Error(message);
  	error.name = 'BadConfigurationError';
  	throw error;
  },

  throwInternalError: function (message) {
  	var error = new Error(message);
  	error.name = 'InternalServerError';
  	throw error;
  },

  throwNotFoundError: function (message) {
  	var error = new Error(message);
  	error.name = 'NotFoundError';
  	error.fNotFound = true;
  	throw error;
  },

  /**
  * Throws an error an sn_ws error when the error type is caught from within one of our services.
  *
  * @param {Error} Caught instance of one of the thrown errors from a function within in this class.
  * The name on the Error parameter indicates which type of sn web error will be thrown.
  *
  * @return {N/A} In all paths an error will be thrown.
  */
  throwSnWsError: function (error) {
  	var errorMessage = "Internal MAB error of type " + error.name + ": " + error.message;

  	if (error.fBadRequest) {
  		throw new sn_ws_err.BadRequestError(errorMessage);
  	} else if (error.fNotFound) {
  		throw new sn_ws_err.NotFoundError(errorMessage);
  	} else {
  		// there is no dedicated sn_ws_err for 500 errors
  		gs.error(errorMessage);
  		throw error; 
  	}
  }
};

Sys ID

37ee05940f362010e70a4abec4767e55

Offical Documentation

Official Docs: