@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.
@@ -1,4 +1,37 @@
1
+ /**
2
+ * @typedef {{
3
+ * type: string,
4
+ * message: string,
5
+ * _code: number,
6
+ * }} _ErrorLike
7
+ */
8
+
9
+ // module vars
10
+ const ErrorCode = {
11
+ NOT_FOUND: 404,
12
+ NOT_SUPPORTED: 505,
13
+ NOT_IMPL: 501
14
+ };
15
+ /**
16
+ * @class _Error
17
+ */
1
18
  class _Error extends Error {
19
+ static get Code () {
20
+ return ErrorCode
21
+ }
22
+
23
+ /**
24
+ * Checks if the given value is an _ErrorLike object
25
+ * @param {{[key:string]:any}} err - The value to checke
26
+ * @returns {boolean} True if the value is error-like
27
+ */
28
+ static isErrorLike (err) {
29
+ if (err == null) {
30
+ return false
31
+ }
32
+ return err._type === '_' && typeof err.code === 'number'
33
+ }
34
+
2
35
  /**
3
36
  * Creates and returns a 404 Not Found error instance with the given message.
4
37
  * @param {string} message - The error message to include.
@@ -38,6 +71,7 @@ class _Error extends Error {
38
71
  */
39
72
  constructor (message, code) {
40
73
  super(message);
74
+ this._type = '_'; // use this to identify if it's _Error
41
75
  this.code = code;
42
76
  }
43
77
  }