UNPKG

1.02 kBJavaScriptView Raw
1'use strict';
2
3/*
4 * Base Camo error.
5 *
6 * Adapted from es6-error package.
7 */
8class CamoError extends Error {
9 constructor(message) {
10 super(message);
11
12 // Extending Error is weird and does not propagate `message`
13 Object.defineProperty(this, 'message', {
14 enumerable : false,
15 value : message
16 });
17
18 Object.defineProperty(this, 'name', {
19 enumerable : false,
20 value : this.constructor.name,
21 });
22
23 if (Error.hasOwnProperty('captureStackTrace')) {
24 Error.captureStackTrace(this, this.constructor);
25 return;
26 }
27
28 Object.defineProperty(this, 'stack', {
29 enumerable : false,
30 value : (new Error(message)).stack,
31 });
32 }
33}
34
35/*
36 * Error indicating document didn't pass validation.
37 */
38class ValidationError extends CamoError {
39 constructor(message) {
40 super(message);
41 }
42}
43
44exports.CamoError = CamoError;
45exports.ValidationError = ValidationError;
\No newline at end of file