ac-custom-error 2.0.2 → 2.0.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.
@@ -1,3 +1,4 @@
1
+
1
2
  # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2
3
  # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3
4
 
@@ -5,28 +6,28 @@ name: Node.js CI
5
6
 
6
7
  on:
7
8
  push:
8
- branches: [ master, develop ]
9
+ branches: [ develop, master ]
9
10
  pull_request:
10
- branches: [ master, develop ]
11
+ branches: [ develop, master ]
11
12
 
12
13
  jobs:
13
14
  build:
14
15
 
15
16
  permissions:
16
- contents: read
17
+ contents: read
17
18
 
18
19
  runs-on: ubuntu-latest
19
20
 
20
21
  strategy:
21
22
  matrix:
22
- node-version: [20.x, 22.x]
23
+ node-version: [22.x, 24.x]
24
+ # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
23
25
 
24
26
  steps:
25
- - uses: actions/checkout@v3
27
+ - uses: actions/checkout@v5
26
28
  - name: Use Node.js ${{ matrix.node-version }}
27
- uses: actions/setup-node@v3
29
+ uses: actions/setup-node@v5
28
30
  with:
29
31
  node-version: ${{ matrix.node-version }}
30
-
31
32
  - run: yarn install
32
33
  - run: yarn run test
package/CHANGELOG.md CHANGED
@@ -1,3 +1,29 @@
1
+ ## [2.0.4](https://github.com/admiralcloud/ac-custom-error/compare/v2.0.3..v2.0.4) (2026-04-17 07:51:29)
2
+
3
+
4
+ ### Bug Fix
5
+
6
+
7
+ * **App:** Package updates | MP | [95c0d5ae365a3812d5b08b2b2971c5e8941f6176](https://github.com/admiralcloud/ac-custom-error/commit/95c0d5ae365a3812d5b08b2b2971c5e8941f6176)
8
+ Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
9
+ ## [2.0.3](https://github.com/admiralcloud/ac-custom-error/compare/v2.0.2..v2.0.3) (2026-04-03 17:01:30)
10
+
11
+
12
+ ### Bug Fix
13
+
14
+
15
+ * **App:** Fixed chaining issue for global.errorCodes | MP | [53006bdee67ca3322f33d62fa36aee850e177a78](https://github.com/admiralcloud/ac-custom-error/commit/53006bdee67ca3322f33d62fa36aee850e177a78)
16
+ Optional chaining on errorCodes to prevent a TypeError when global.errorCodes is undefined.
17
+ Related issues:
18
+ * **App:** Package updates | MP | [be06bb2eb36de0f3acd4b64e48caa01f1a92ba4a](https://github.com/admiralcloud/ac-custom-error/commit/be06bb2eb36de0f3acd4b64e48caa01f1a92ba4a)
19
+ Package updates
20
+ Related issues:
21
+ ### Chores
22
+
23
+
24
+ * **App:** Updated Github actions | MP | [f87a97de35e910301f5d407ba794c15596088a1a](https://github.com/admiralcloud/ac-custom-error/commit/f87a97de35e910301f5d407ba794c15596088a1a)
25
+ Updated Github actions
26
+ Related issues:
1
27
 
2
28
  ## [2.0.2](https://github.com/admiralcloud/ac-custom-error/compare/v2.0.1..v2.0.2) (2026-02-28 12:02:22)
3
29
 
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # AC-Custom-Error
2
2
  Extend the NodeJS error with an error code and additional information.
3
3
 
4
- [![Node.js CI](https://github.com/AdmiralCloud/ac-custom-error/actions/workflows/node.js.yml/badge.svg)](https://github.com/AdmiralCloud/ac-custom-error/actions/workflows/node.js.yml)
4
+ [![Node.js CI](https://github.com/AdmiralCloud/ac-custom-error/actions/workflows/node.js.yml/badge.svg)](https://github.com/AdmiralCloud/ac-custom-error/actions/workflows/node.js.yml) [![CodeQL](https://github.com/AdmiralCloud/ac-custom-error/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/AdmiralCloud/ac-custom-error/actions/workflows/github-code-scanning/codeql)
5
5
 
6
6
  # ACErrorFromCode
7
7
  This is the preferred way to use this class. You define a central library of error codes and export them to global. You can then throw the error based on that code.
package/index.js CHANGED
@@ -27,7 +27,7 @@ class ACErrorFromCode extends Error {
27
27
  super(code)
28
28
 
29
29
  // fetch the error message for errorCodes object (if available)
30
- const error = global?.errorCodes[code]
30
+ const error = global?.errorCodes?.[code]
31
31
 
32
32
  if (Error.captureStackTrace) {
33
33
  Error.captureStackTrace(this, ACErrorFromCode)
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "ac-custom-error",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "description": "Custom NodeJS error with error code and additional info",
5
5
  "main": "index.js",
6
6
  "repository": "https://github.com/AdmiralCloud/ac-custom-error",
7
7
  "author": "Mark Poepping (www.admiralcloud.com)",
8
8
  "license": "MIT",
9
9
  "devDependencies": {
10
- "ac-semantic-release": "^0.4.10",
10
+ "ac-semantic-release": "^1.0.2",
11
11
  "chai": "^4.5.0",
12
- "eslint": "^10.0.2",
13
- "globals": "^17.3.0",
12
+ "eslint": "^10.2.0",
13
+ "globals": "^17.5.0",
14
14
  "mocha": "^11.7.5",
15
15
  "nyc": "^18.0.0"
16
16
  },
package/test.js CHANGED
@@ -23,7 +23,9 @@ describe('Run tests with ACError', () => {
23
23
  error = err
24
24
  }
25
25
  expect(error).to.be.an('Error')
26
+ expect(error).to.be.instanceOf(ACError)
26
27
  expect(error.message).to.equal(errorParams.message)
28
+ expect(error.errorMessage).to.equal(errorParams.message)
27
29
  expect(error.code).to.equal(errorParams.code)
28
30
  })
29
31
 
@@ -57,11 +59,36 @@ describe('Run tests with ACError', () => {
57
59
  expect(error.options).to.have.property('stack', errorParams.options.stack)
58
60
  })
59
61
 
62
+ it('Check default code -1 when no code is provided', () => {
63
+ let errorParams = { message: 'myError' }
64
+ let error
65
+ try {
66
+ errorFunction(errorParams)
67
+ }
68
+ catch (err) {
69
+ error = err
70
+ }
71
+ expect(error).to.be.an('Error')
72
+ expect(error.code).to.equal(-1)
73
+ })
74
+
75
+ it('Check that additionalInfo is not set when empty', () => {
76
+ let errorParams = { message: 'myError', code: 123 }
77
+ let error
78
+ try {
79
+ errorFunction(errorParams)
80
+ }
81
+ catch (err) {
82
+ error = err
83
+ }
84
+ expect(error.additionalInfo).to.be.undefined
85
+ })
86
+
60
87
  })
61
88
 
62
- describe('Run tests with ACError', () => {
89
+ describe('Run tests with ACErrorFromCode', () => {
63
90
 
64
- it('Define error codes', () => {
91
+ before(() => {
65
92
  global.errorCodes = {
66
93
  123: {
67
94
  message: 'thisIsAnError',
@@ -70,6 +97,9 @@ describe('Run tests with ACError', () => {
70
97
  }
71
98
  })
72
99
 
100
+ after(() => {
101
+ delete global.errorCodes
102
+ })
73
103
 
74
104
  it('Check error', () => {
75
105
  let error
@@ -79,13 +109,68 @@ describe('Run tests with ACError', () => {
79
109
  catch (err) {
80
110
  error = err
81
111
  }
82
-
112
+
83
113
  expect(error).to.be.an('Error')
114
+ expect(error).to.be.instanceOf(ACErrorFromCode)
84
115
  expect(error.message).to.equal(global.errorCodes[123].message)
116
+ expect(error.errorMessage).to.equal(global.errorCodes[123].message)
85
117
  expect(error.code).to.equal(123)
86
118
  expect(error.solution).to.equal(global.errorCodes[123].solution)
87
119
  })
88
120
 
121
+ it('Check error with additionalInfo', () => {
122
+ let error
123
+ try {
124
+ errorFunctionFromCode({ code: 123, additionalInfo: { field: 'userId' } })
125
+ }
126
+ catch (err) {
127
+ error = err
128
+ }
129
+
130
+ expect(error).to.be.an('Error')
131
+ expect(error.additionalInfo).to.deep.equal({ field: 'userId' })
132
+ })
133
+
134
+ it('Check default code -1 when no code is provided', () => {
135
+ let error
136
+ try {
137
+ errorFunctionFromCode({})
138
+ }
139
+ catch (err) {
140
+ error = err
141
+ }
142
+
143
+ expect(error).to.be.an('Error')
144
+ expect(error.code).to.equal(-1)
145
+ })
146
+
147
+ it('Check fallback errorMessage for unknown code', () => {
148
+ let error
149
+ try {
150
+ errorFunctionFromCode({ code: 999 })
151
+ }
152
+ catch (err) {
153
+ error = err
154
+ }
155
+
156
+ expect(error).to.be.an('Error')
157
+ expect(error.errorMessage).to.equal('undefinedError')
158
+ expect(error.solution).to.be.undefined
159
+ })
160
+
161
+ it('Check that ACErrorFromCode works when global.errorCodes is not defined', () => {
162
+ delete global.errorCodes
163
+ let error
164
+ try {
165
+ errorFunctionFromCode({ code: 123 })
166
+ }
167
+ catch (err) {
168
+ error = err
169
+ }
170
+
171
+ expect(error).to.be.an('Error')
172
+ expect(error.errorMessage).to.equal('undefinedError')
173
+ })
89
174
 
90
175
  })
91
176