error-message-utils 1.1.0 → 1.1.2
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.
- package/README.md +29 -30
- package/dist/index.d.ts +1 -1
- package/dist/shared/types.d.ts +9 -9
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -12,16 +12,10 @@ The `error-message-utils` package simplifies error management in your web applic
|
|
|
12
12
|
|
|
13
13
|
Install the package:
|
|
14
14
|
```bash
|
|
15
|
-
|
|
15
|
+
npm install -S error-message-utils
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
</br>
|
|
23
|
-
|
|
24
|
-
## Usage
|
|
18
|
+
### Examples
|
|
25
19
|
|
|
26
20
|
Encoding an error:
|
|
27
21
|
|
|
@@ -100,42 +94,47 @@ isEncodedError(encodeError(new Error('Some unknown error.'), 'NASTY_ERROR'));
|
|
|
100
94
|
```
|
|
101
95
|
|
|
102
96
|
|
|
103
|
-
<br/>
|
|
104
|
-
|
|
105
|
-
## Built With
|
|
106
|
-
|
|
107
|
-
- TypeScript
|
|
108
|
-
|
|
109
|
-
|
|
110
97
|
|
|
111
98
|
|
|
112
99
|
<br/>
|
|
113
100
|
|
|
114
|
-
##
|
|
101
|
+
## Types
|
|
115
102
|
|
|
116
|
-
```
|
|
117
|
-
|
|
103
|
+
```typescript
|
|
104
|
+
/**
|
|
105
|
+
* Error Code
|
|
106
|
+
* The code that is inserted when encoding an error. If none is provided or none can be extracted, it defaults to -1.
|
|
107
|
+
*/
|
|
108
|
+
type IErrorCode = string | number;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Decoded Error
|
|
112
|
+
* The object obtained when an error is decoded. Keep in mind that if the error message or the code cannot be extracted for any reason, the default values will be set instead.
|
|
113
|
+
*/
|
|
114
|
+
type IDecodedError = {
|
|
115
|
+
message: string,
|
|
116
|
+
code: IErrorCode,
|
|
117
|
+
};
|
|
118
118
|
```
|
|
119
119
|
|
|
120
120
|
|
|
121
121
|
|
|
122
|
-
|
|
123
|
-
|
|
124
122
|
<br/>
|
|
125
123
|
|
|
126
|
-
##
|
|
127
|
-
|
|
128
|
-
[MIT](https://choosealicense.com/licenses/mit/)
|
|
124
|
+
## Built With
|
|
129
125
|
|
|
126
|
+
- TypeScript
|
|
130
127
|
|
|
131
128
|
|
|
132
129
|
|
|
133
130
|
|
|
134
131
|
<br/>
|
|
135
132
|
|
|
136
|
-
##
|
|
133
|
+
## Running the Tests
|
|
137
134
|
|
|
138
|
-
|
|
135
|
+
```bash
|
|
136
|
+
npm run test:unit
|
|
137
|
+
```
|
|
139
138
|
|
|
140
139
|
|
|
141
140
|
|
|
@@ -143,9 +142,9 @@ $ npm run test:unit
|
|
|
143
142
|
|
|
144
143
|
<br/>
|
|
145
144
|
|
|
146
|
-
##
|
|
145
|
+
## License
|
|
147
146
|
|
|
148
|
-
|
|
147
|
+
[MIT](https://choosealicense.com/licenses/mit/)
|
|
149
148
|
|
|
150
149
|
|
|
151
150
|
|
|
@@ -157,17 +156,17 @@ $ npm run test:unit
|
|
|
157
156
|
|
|
158
157
|
Install dependencies:
|
|
159
158
|
```bash
|
|
160
|
-
|
|
159
|
+
npm install
|
|
161
160
|
```
|
|
162
161
|
|
|
163
162
|
|
|
164
163
|
Build the library:
|
|
165
164
|
```bash
|
|
166
|
-
|
|
165
|
+
npm start
|
|
167
166
|
```
|
|
168
167
|
|
|
169
168
|
|
|
170
169
|
Publish to `npm`:
|
|
171
170
|
```bash
|
|
172
|
-
|
|
171
|
+
npm publish
|
|
173
172
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -26,4 +26,4 @@ declare const decodeError: (error: any) => IDecodedError;
|
|
|
26
26
|
* @returns boolean
|
|
27
27
|
*/
|
|
28
28
|
declare const isEncodedError: (error: any) => boolean;
|
|
29
|
-
export { IErrorCode, IDecodedError, extractMessage, encodeError, decodeError, isEncodedError, };
|
|
29
|
+
export { type IErrorCode, type IDecodedError, extractMessage, encodeError, decodeError, isEncodedError, };
|
package/dist/shared/types.d.ts
CHANGED
|
@@ -3,31 +3,31 @@
|
|
|
3
3
|
* When an error code is inserted into a message (encoding a message), it must be wrapped first so
|
|
4
4
|
* it can be decoded later.
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
type IErrorCodeWrapper = {
|
|
7
7
|
prefix: string;
|
|
8
8
|
suffix: string;
|
|
9
|
-
}
|
|
9
|
+
};
|
|
10
10
|
/**
|
|
11
11
|
* Error Code
|
|
12
|
-
* The
|
|
13
|
-
*
|
|
12
|
+
* The code that is inserted when encoding an error. If none is provided or none can be extracted,
|
|
13
|
+
* it defaults to -1.
|
|
14
14
|
*/
|
|
15
15
|
type IErrorCode = string | number;
|
|
16
16
|
/**
|
|
17
17
|
* Unwrapped Error Code
|
|
18
18
|
* In order to decode an error, the code must be first unwrapped.
|
|
19
19
|
*/
|
|
20
|
-
|
|
20
|
+
type IUnwrappedErrorCode = {
|
|
21
21
|
code: IErrorCode;
|
|
22
22
|
startsAt: number;
|
|
23
|
-
}
|
|
23
|
+
};
|
|
24
24
|
/**
|
|
25
25
|
* Decoded Error
|
|
26
26
|
* The object obtained when an error is decoded. Keep in mind that if the error message or the code
|
|
27
27
|
* cannot be extracted for any reason, the default values will be set instead.
|
|
28
28
|
*/
|
|
29
|
-
|
|
29
|
+
type IDecodedError = {
|
|
30
30
|
message: string;
|
|
31
31
|
code: IErrorCode;
|
|
32
|
-
}
|
|
33
|
-
export { IErrorCodeWrapper, IErrorCode, IUnwrappedErrorCode, IDecodedError, };
|
|
32
|
+
};
|
|
33
|
+
export type { IErrorCodeWrapper, IErrorCode, IUnwrappedErrorCode, IDecodedError, };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "error-message-utils",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "The error-message-utils package simplifies error management in your web applications and RESTful APIs. It ensures consistent and scalable handling of error messages, saving you time and effort. Moreover, it gives you the ability to assign custom error codes so all possible cases can be handled accordingly.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -37,14 +37,14 @@
|
|
|
37
37
|
},
|
|
38
38
|
"homepage": "https://github.com/jesusgraterol/error-message-utils#readme",
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@types/jest": "^29.5.
|
|
41
|
-
"@types/node": "^20.
|
|
42
|
-
"@typescript-eslint/eslint-plugin": "^7.
|
|
43
|
-
"@typescript-eslint/parser": "^7.
|
|
40
|
+
"@types/jest": "^29.5.14",
|
|
41
|
+
"@types/node": "^20.17.9",
|
|
42
|
+
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
|
43
|
+
"@typescript-eslint/parser": "^7.18.0",
|
|
44
44
|
"eslint-config-airbnb-typescript": "^18.0.0",
|
|
45
45
|
"jest": "^29.7.0",
|
|
46
|
-
"ts-jest": "^29.
|
|
47
|
-
"ts-lib-builder": "^1.0.
|
|
48
|
-
"typescript": "^5.
|
|
46
|
+
"ts-jest": "^29.2.5",
|
|
47
|
+
"ts-lib-builder": "^1.0.5",
|
|
48
|
+
"typescript": "^5.7.2"
|
|
49
49
|
}
|
|
50
50
|
}
|