All files / ima/error GenericError.js

100% Statements 6/6
75% Branches 3/4
100% Functions 3/3
100% Lines 6/6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52      23x                                           134x             134x             8x             94x       23x  
import ns from '../namespace';
import Error from './Error';
 
ns.namespace('ima.error');
 
/**
 * Implementation of the ima.error.Error interface, providing more advanced
 * error API.
 */
export default class GenericError extends Error {
  /**
	 * Initializes the generic IMA error.
	 *
	 * @param {string} message The message describing the cause of the error.
	 * @param {Object<string, *>=} [params={}] A data map providing additional
	 *        details related to the error. It is recommended to set the
	 *        {@code status} field to the HTTP response code that should be sent
	 *        to the client.
	 * @param {boolean=} dropInternalStackFrames Whether or not the call stack
	 *        frames referring to the constructors of the custom errors should
	 *        be excluded from the stack of this error (just like the native
	 *        platform call stack frames are dropped by the JS engine).
	 *        This flag is enabled by default.
	 */
  constructor(message, params = {}, dropInternalStackFrames = true) {
    super(message, dropInternalStackFrames);
 
    /**
		 * The data providing additional details related to this error.
		 *
		 * @type {Object<string, *>}
		 */
    this._params = params;
  }
 
  /**
	 * @inheritdoc
	 */
  getHttpStatus() {
    return this._params.status || 500;
  }
 
  /**
	 * @inheritdoc
	 */
  getParams() {
    return this._params;
  }
}
 
ns.ima.error.GenericError = GenericError;