error-message-utils 1.0.1 → 1.0.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 CHANGED
@@ -75,7 +75,7 @@ extractMessage({
75
75
 
76
76
  ## Built With
77
77
 
78
- - JavaScript / TypeScript
78
+ - TypeScript
79
79
 
80
80
 
81
81
 
@@ -1,4 +1,4 @@
1
- import { IErrorCode, IDecodedError } from './types.js';
1
+ import { IErrorCode, IDecodedError } from '../shared/index.js';
2
2
  /**
3
3
  * Attempts to extract an error message from an error that could be anything. If it fails to do so,
4
4
  * it returns the default message.
@@ -0,0 +1 @@
1
+ import{DEFAULT_MESSAGE,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}};export{extractMessage,encodeError,decodeError};
@@ -0,0 +1 @@
1
+ export * from './error.js';
@@ -0,0 +1 @@
1
+ export*from"./error.js";
package/dist/index.d.ts CHANGED
@@ -1 +1,2 @@
1
- export * from './message/index.js';
1
+ export * from './shared/types.js';
2
+ export * from './error/index.js';
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export*from"./message/index.js";
1
+ export*from"./shared/types.js";export*from"./error/index.js";
@@ -0,0 +1 @@
1
+ export * from './types.js';
@@ -0,0 +1 @@
1
+ export*from"./types.js";
@@ -0,0 +1 @@
1
+ export{};
@@ -0,0 +1 @@
1
+ export * from './utils.js';
@@ -0,0 +1 @@
1
+ export*from"./utils.js";
@@ -1,4 +1,4 @@
1
- import { IErrorCodeWrapper, IErrorCode, IUnwrappedErrorCode } from './types.js';
1
+ import { IErrorCodeWrapper, IErrorCode, IUnwrappedErrorCode } from '../shared/index.js';
2
2
  declare const CODE_WRAPPER: IErrorCodeWrapper;
3
3
  declare const DEFAULT_MESSAGE: string;
4
4
  declare const DEFAULT_CODE: IErrorCode;
@@ -0,0 +1 @@
1
+ const CODE_WRAPPER={prefix:"{(",suffix:")}"},DEFAULT_MESSAGE="The error message could not be extracted, check the logs for more information.",DEFAULT_CODE=-1,wrapCode=e=>`${CODE_WRAPPER.prefix}${e??-1}${CODE_WRAPPER.suffix}`,__isEncodedError=e=>new RegExp(`${CODE_WRAPPER.prefix}.+${CODE_WRAPPER.suffix}$`).test(e),__isNumeric=e=>!Number.isNaN(Number.parseFloat(e)),unwrapCode=e=>{if(__isEncodedError(e)){const r=e.lastIndexOf(CODE_WRAPPER.prefix),E=e.substring(r+2,e.lastIndexOf(CODE_WRAPPER.suffix));return{code:__isNumeric(E)?Number(E):E,startsAt:r}}return{code:-1,startsAt:-1}};export{CODE_WRAPPER,DEFAULT_MESSAGE,DEFAULT_CODE,wrapCode,unwrapCode};
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "error-message-utils",
3
- "version": "1.0.1",
3
+ "version": "1.0.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",
7
7
  "type": "module",
8
8
  "scripts": {
9
- "start": "ts-lib-builder --tsconfigPath=tsconfig.build.json",
9
+ "start": "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"
@@ -44,7 +44,7 @@
44
44
  "eslint-config-airbnb-typescript": "^18.0.0",
45
45
  "jest": "^29.7.0",
46
46
  "ts-jest": "^29.1.2",
47
- "ts-lib-builder": "^1.0.2",
47
+ "ts-lib-builder": "^1.0.3",
48
48
  "typescript": "^5.4.5"
49
49
  }
50
50
  }
@@ -1,2 +0,0 @@
1
- export * from './types.js';
2
- export * from './message.js';
@@ -1 +0,0 @@
1
- export*from"./types.js";export*from"./message.js";
@@ -1 +0,0 @@
1
- import{DEFAULT_MESSAGE,wrapCode,unwrapCode}from"./message.utils.js";const extractMessage=e=>{if("string"==typeof e&&e.length)return e;if(e instanceof Error&&e.message)return e.cause?e.message+"; [CAUSE]: "+extractMessage(e.cause):e.message;if(e&&"object"==typeof e){if(e.message)return extractMessage(e.message);if(e.msg)return extractMessage(e.msg);if(e.error)return extractMessage(e.error);if(e.err)return extractMessage(e.err);if(e.errors)return extractMessage(e.errors);if(e.errs)return extractMessage(e.errs);try{return JSON.stringify(e)}catch(r){console.error("Error during extractMessage:"),console.error("Original Error: ",e),console.error("JSON.stringify Error:",r)}}return DEFAULT_MESSAGE},encodeError=(r,e)=>""+extractMessage(r)+wrapCode(e),decodeError=r=>{var r=extractMessage(r),{code:e,startsAt:s}=unwrapCode(r);return{message:0<s?r.slice(0,s):r,code:e}};export{extractMessage,encodeError,decodeError};
@@ -1 +0,0 @@
1
- const CODE_WRAPPER={prefix:"{(",suffix:")}"},DEFAULT_MESSAGE="The error message could not be extracted, check the logs for more information.",DEFAULT_CODE=-1,wrapCode=e=>""+CODE_WRAPPER.prefix+(e??DEFAULT_CODE)+CODE_WRAPPER.suffix,__isEncodedError=e=>new RegExp(`${CODE_WRAPPER.prefix}.+${CODE_WRAPPER.suffix}$`).test(e),__isNumeric=e=>!Number.isNaN(Number.parseFloat(e)),unwrapCode=e=>{var r;return __isEncodedError(e)?(r=e.lastIndexOf(CODE_WRAPPER.prefix),e=e.substring(r+2,e.lastIndexOf(CODE_WRAPPER.suffix)),{code:__isNumeric(e)?Number(e):e,startsAt:r}):{code:-1,startsAt:-1}};export{CODE_WRAPPER,DEFAULT_MESSAGE,DEFAULT_CODE,wrapCode,unwrapCode};
File without changes
File without changes