Constructor
new ErrorMessage(code, desc)
Creates new ErrorMessage object out of an error code and an error description template.
Parameters:
Name | Type | Description |
---|---|---|
code |
number | error code |
desc |
string | error description template with $-based placeholders such as $1, $2, etc. |
- Since:
- 0.1.0
- Source:
Throws:
- Type
- Error
Example
var ILLEGAL_ARGUMENT = new services.ErrorMessage(1000, 'Illegal argument(s). $1'); // $1 is a placeholder
Methods
isTypeOf(error) → {boolean}
Checks whether the given Error object has error code in its message property equal to the error code of this ErrorMessage object.
Parameters:
Name | Type | Description |
---|---|---|
error |
Error | Error object to check its error code |
- Since:
- 0.1.0
- Source:
Returns:
whether the given Error object has error code in its message property equal to the error code of this ErrorMessage object
- Type
- boolean
Example
var ILLEGAL_ARGUMENT = new services.ErrorMessage(1000, 'Illegal argument(s). $1');
try {
throw new Error(ILLEGAL_ARGUMENT.toString('Not a number!'));
} catch (err){
console.log(ILLEGAL_ARGUMENT.isTypeOf(err)); // true
}
toString(…replacement) → {string}
Creates error message text (string) based on the error code, the error description template, and the given placeholder replacement strings.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
replacement |
string |
<repeatable> |
error message placeholder replacement string |
- Since:
- 0.1.0
- Source:
Returns:
error message text for this ErrorMessage object and the given placeholder replacements
- Type
- string
Example
var ILLEGAL_ARGUMENT = new services.ErrorMessage(1000, 'Illegal argument(s). $1');
...
throw new Error(ILLEGAL_ARGUMENT.toString('Not a number!')); // "Oops! Illegal argument(s). Not a number! (#1000)"