@creejs/commons-lang 2.1.23 → 2.1.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,40 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ /**
6
+ * @typedef {{
7
+ * type: string,
8
+ * message: string,
9
+ * _code: number,
10
+ * }} _ErrorLike
11
+ */
12
+
13
+ // module vars
14
+ const ErrorCode = {
15
+ NOT_FOUND: 404,
16
+ NOT_SUPPORTED: 505,
17
+ NOT_IMPL: 501
18
+ };
19
+ /**
20
+ * @class _Error
21
+ */
5
22
  class _Error extends Error {
23
+ static get Code () {
24
+ return ErrorCode
25
+ }
26
+
27
+ /**
28
+ * Checks if the given value is an _ErrorLike object
29
+ * @param {{[key:string]:any}} err - The value to checke
30
+ * @returns {boolean} True if the value is error-like
31
+ */
32
+ static isErrorLike (err) {
33
+ if (err == null) {
34
+ return false
35
+ }
36
+ return err._type === '_' && typeof err.code === 'number'
37
+ }
38
+
6
39
  /**
7
40
  * Creates and returns a 404 Not Found error instance with the given message.
8
41
  * @param {string} message - The error message to include.
@@ -42,6 +75,7 @@ class _Error extends Error {
42
75
  */
43
76
  constructor (message, code) {
44
77
  super(message);
78
+ this._type = '_'; // use this to identify if it's _Error
45
79
  this.code = code;
46
80
  }
47
81
  }