error-message-utils 1.1.2 → 1.1.4
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/.prettierignore +35 -0
- package/.prettierrc +12 -0
- package/README.md +21 -26
- package/dist/index.d.ts +8 -1
- package/dist/index.js +1 -1
- package/dist/shared/types.d.ts +1 -1
- package/package.json +13 -11
package/.prettierignore
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# defaults
|
|
2
|
+
**/.git
|
|
3
|
+
**/.svn
|
|
4
|
+
**/.hg
|
|
5
|
+
**/node_modules
|
|
6
|
+
|
|
7
|
+
# build and dist Output
|
|
8
|
+
dist
|
|
9
|
+
build
|
|
10
|
+
.out
|
|
11
|
+
.next
|
|
12
|
+
|
|
13
|
+
# logs
|
|
14
|
+
npm-debug.log
|
|
15
|
+
yarn-debug.log
|
|
16
|
+
yarn-error.log
|
|
17
|
+
pnpm-debug.log
|
|
18
|
+
|
|
19
|
+
# environment files
|
|
20
|
+
.env
|
|
21
|
+
.env.local
|
|
22
|
+
.env.*.local
|
|
23
|
+
|
|
24
|
+
# lockfiles (if using a monorepo or specific package manager setup)
|
|
25
|
+
package-lock.json
|
|
26
|
+
yarn.lock
|
|
27
|
+
pnpm-lock.yaml
|
|
28
|
+
|
|
29
|
+
# miscellaneous
|
|
30
|
+
coverage/
|
|
31
|
+
.DS_Store
|
|
32
|
+
*.min.js
|
|
33
|
+
public/
|
|
34
|
+
tmp/
|
|
35
|
+
*.md
|
package/.prettierrc
ADDED
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ The `error-message-utils` package simplifies error management in your web applic
|
|
|
12
12
|
|
|
13
13
|
Install the package:
|
|
14
14
|
```bash
|
|
15
|
-
npm
|
|
15
|
+
npm i -S error-message-utils
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
### Examples
|
|
@@ -94,6 +94,26 @@ isEncodedError(encodeError(new Error('Some unknown error.'), 'NASTY_ERROR'));
|
|
|
94
94
|
```
|
|
95
95
|
|
|
96
96
|
|
|
97
|
+
<br/>
|
|
98
|
+
|
|
99
|
+
In some cases, you may want to check whether the extracted error matches the default message provided by this package:
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
import { isDefaultErrorMessage} from 'error-message-utils';
|
|
103
|
+
|
|
104
|
+
const DEFAULT_MESSAGE: string = 'The error message could not be extracted, check the logs for more information.';
|
|
105
|
+
|
|
106
|
+
isDefaultErrorMessage(DEFAULT_MESSAGE);
|
|
107
|
+
// true
|
|
108
|
+
|
|
109
|
+
isDefaultErrorMessage(`${DEFAULT_MESSAGE} and something else...`);
|
|
110
|
+
// false
|
|
111
|
+
|
|
112
|
+
isDefaultErrorMessage(`${DEFAULT_MESSAGE} and something else...`, true);
|
|
113
|
+
// true
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
|
|
97
117
|
|
|
98
118
|
|
|
99
119
|
<br/>
|
|
@@ -145,28 +165,3 @@ npm run test:unit
|
|
|
145
165
|
## License
|
|
146
166
|
|
|
147
167
|
[MIT](https://choosealicense.com/licenses/mit/)
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
<br/>
|
|
154
|
-
|
|
155
|
-
## Deployment
|
|
156
|
-
|
|
157
|
-
Install dependencies:
|
|
158
|
-
```bash
|
|
159
|
-
npm install
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
Build the library:
|
|
164
|
-
```bash
|
|
165
|
-
npm start
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
Publish to `npm`:
|
|
170
|
-
```bash
|
|
171
|
-
npm publish
|
|
172
|
-
```
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,13 @@ import { IErrorCode, IDecodedError } from './shared/types.js';
|
|
|
6
6
|
* @returns string
|
|
7
7
|
*/
|
|
8
8
|
declare const extractMessage: (error: any) => string;
|
|
9
|
+
/**
|
|
10
|
+
* Verifies if a value matches the default error message used by this package.
|
|
11
|
+
* @param value
|
|
12
|
+
* @param fullMatch?
|
|
13
|
+
* @returns boolean
|
|
14
|
+
*/
|
|
15
|
+
declare const isDefaultErrorMessage: (value: string, fullMatch?: boolean) => value is string;
|
|
9
16
|
/**
|
|
10
17
|
* Given an error in any format, it extracts the message and inserts the code at the end.
|
|
11
18
|
* @param error
|
|
@@ -26,4 +33,4 @@ declare const decodeError: (error: any) => IDecodedError;
|
|
|
26
33
|
* @returns boolean
|
|
27
34
|
*/
|
|
28
35
|
declare const isEncodedError: (error: any) => boolean;
|
|
29
|
-
export { type IErrorCode, type IDecodedError, extractMessage, encodeError, decodeError, isEncodedError, };
|
|
36
|
+
export { type IErrorCode, type IDecodedError, extractMessage, isDefaultErrorMessage, encodeError, decodeError, isEncodedError, };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{DEFAULT_MESSAGE,DEFAULT_CODE,wrapCode,unwrapCode}from"./utils/utils.js";const extractMessage=r=>{if("string"==typeof r&&r.length)return r;if(r instanceof Error&&r.message)return r.cause?`${r.message}; [CAUSE]: ${extractMessage(r.cause)}`:r.message;if(r&&"object"==typeof r){if(r.message)return extractMessage(r.message);if(r.msg)return extractMessage(r.msg);if(r.error)return extractMessage(r.error);if(r.err)return extractMessage(r.err);if(r.errors)return extractMessage(r.errors);if(r.errs)return extractMessage(r.errs);try{return JSON.stringify(r)}catch(e){console.error("Error during extractMessage:"),console.error("Original Error: ",r),console.error("JSON.stringify Error:",e)}}return DEFAULT_MESSAGE},encodeError=(r,e)=>`${extractMessage(r)}${wrapCode(e)}`,decodeError=r=>{const e=extractMessage(r),{code:s,startsAt:t}=unwrapCode(e);return{message:t>0?e.slice(0,t):e,code:s}},isEncodedError=r=>decodeError(r).code!==DEFAULT_CODE;export{extractMessage,encodeError,decodeError,isEncodedError};
|
|
1
|
+
import{DEFAULT_MESSAGE,DEFAULT_CODE,wrapCode,unwrapCode}from"./utils/utils.js";const extractMessage=r=>{if("string"==typeof r&&r.length)return r;if(r instanceof Error&&r.message)return r.cause?`${r.message}; [CAUSE]: ${extractMessage(r.cause)}`:r.message;if(r&&"object"==typeof r){if(r.message)return extractMessage(r.message);if(r.msg)return extractMessage(r.msg);if(r.error)return extractMessage(r.error);if(r.err)return extractMessage(r.err);if(r.errors)return extractMessage(r.errors);if(r.errs)return extractMessage(r.errs);try{return JSON.stringify(r)}catch(e){console.error("Error during extractMessage:"),console.error("Original Error: ",r),console.error("JSON.stringify Error:",e)}}return DEFAULT_MESSAGE},isDefaultErrorMessage=(r,e=!1)=>e?r===DEFAULT_MESSAGE:"string"==typeof r&&r.includes(DEFAULT_MESSAGE),encodeError=(r,e)=>`${extractMessage(r)}${wrapCode(e)}`,decodeError=r=>{const e=extractMessage(r),{code:s,startsAt:t}=unwrapCode(e);return{message:t>0?e.slice(0,t):e,code:s}},isEncodedError=r=>decodeError(r).code!==DEFAULT_CODE;export{extractMessage,isDefaultErrorMessage,encodeError,decodeError,isEncodedError};
|
package/dist/shared/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "error-message-utils",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
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",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"
|
|
9
|
+
"build": "ts-lib-builder --tsconfig=tsconfig.build.json",
|
|
10
10
|
"test": "echo \"Error: tests are executed with npm run test:(integration|unit)\" && exit 1",
|
|
11
11
|
"test:integration": "jest --config=jest.test-integration.config.json --no-cache",
|
|
12
12
|
"test:unit": "jest --config=jest.test-unit.config.json --no-cache"
|
|
@@ -37,14 +37,16 @@
|
|
|
37
37
|
},
|
|
38
38
|
"homepage": "https://github.com/jesusgraterol/error-message-utils#readme",
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@types/jest": "
|
|
41
|
-
"@types/node": "
|
|
42
|
-
"@typescript-eslint/eslint-plugin": "
|
|
43
|
-
"@typescript-eslint/parser": "
|
|
44
|
-
"eslint-config-airbnb-typescript": "
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
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
|
+
"eslint-config-airbnb-typescript": "18.0.0",
|
|
45
|
+
"eslint-config-prettier": "10.1.5",
|
|
46
|
+
"jest": "29.7.0",
|
|
47
|
+
"prettier": "3.6.2",
|
|
48
|
+
"ts-jest": "29.2.5",
|
|
49
|
+
"ts-lib-builder": "1.0.7",
|
|
50
|
+
"typescript": "5.7.2"
|
|
49
51
|
}
|
|
50
52
|
}
|