ac-custom-error 0.1.0

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/.acsemver ADDED
@@ -0,0 +1,9 @@
1
+ module.exports = {
2
+ repository: {
3
+ url: 'https://github.com/admiralcloud/ac-custom-error'
4
+ },
5
+ changelogFile: __dirname + '/CHANGELOG.md',
6
+ sections: [
7
+ { name: 'App' }
8
+ ],
9
+ }
package/.eslintrc.js ADDED
@@ -0,0 +1,28 @@
1
+ const config = {
2
+ root: true,
3
+ 'env': {
4
+ 'commonjs': true,
5
+ 'es6': true,
6
+ 'node': true
7
+ },
8
+ 'extends': 'eslint:recommended',
9
+ "rules": {
10
+ "space-before-function-paren": 0,
11
+ "no-extra-semi": 0,
12
+ "object-curly-spacing": ["error", "always"],
13
+ "brace-style": ["error", "stroustrup", { "allowSingleLine": true }],
14
+ "no-useless-escape": 0,
15
+ "standard/no-callback-literal": 0,
16
+ "new-cap": 0,
17
+ "no-console": ["error", { allow: ["error"] }]
18
+ },
19
+ 'parserOptions': {
20
+ 'ecmaVersion': 2022
21
+ },
22
+ globals: {
23
+ describe: true,
24
+ it: true
25
+ }
26
+ }
27
+
28
+ module.exports = config
@@ -0,0 +1,29 @@
1
+ # 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
+ # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3
+
4
+ name: Node.js CI
5
+
6
+ on:
7
+ push:
8
+ branches: [ master, develop ]
9
+ pull_request:
10
+ branches: [ master, develop ]
11
+
12
+ jobs:
13
+ build:
14
+
15
+ runs-on: ubuntu-latest
16
+
17
+ strategy:
18
+ matrix:
19
+ node-version: [16.x, 18.x]
20
+
21
+ steps:
22
+ - uses: actions/checkout@v3
23
+ - name: Use Node.js ${{ matrix.node-version }}
24
+ uses: actions/setup-node@v3
25
+ with:
26
+ node-version: ${{ matrix.node-version }}
27
+
28
+ - run: yarn install
29
+ - run: yarn run test
package/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ <a name="0.1.0"></a>
2
+
3
+ # [0.1.0](https://github.com/admiralcloud/ac-custom-error/compare/..v0.1.0) (2023-03-10 13:45:10)
4
+
5
+
6
+ ### Feature
7
+
8
+ * **App:** Initial version | MP | [3cc542e6e22fbda35f964e557fbadaaf622e24e1](https://github.com/admiralcloud/ac-custom-error/commit/3cc542e6e22fbda35f964e557fbadaaf622e24e1)
9
+ Initial version
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 AdmiralCloud
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/Makefile ADDED
@@ -0,0 +1,17 @@
1
+ MOCHA_OPTS= --slow 0 -A
2
+ REPORTER = spec
3
+
4
+ lint-fix:
5
+ ./node_modules/.bin/eslint --fix index.js test.js
6
+
7
+ lint-check:
8
+ ./node_modules/.bin/eslint index.js test.js
9
+
10
+ commit:
11
+ @node ./node_modules/ac-semantic-release/lib/commit.js
12
+
13
+ release:
14
+ @node ./node_modules/ac-semantic-release/lib/release.js
15
+
16
+
17
+ .PHONY: check
package/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # AC-Custom-Error
2
+ Extend the NodeJS error with an error code and additional information.
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)
5
+
6
+ # Usage
7
+ ```
8
+ const ACError = require('ac-custom-error')
9
+
10
+ throw new ACError('myError', 123, { id: 333 })
11
+
12
+ // OUTPUT
13
+ ACError: myError
14
+ at STACK
15
+ code: 123,
16
+ errorMessage: 'myError',
17
+ additionalInfo: { id: 333 }
18
+ }
19
+
20
+ ```
21
+
22
+
23
+ # Links
24
+ - [Website](https://www.admiralcloud.com/)
25
+
26
+ # License
27
+ [MIT License](https://opensource.org/licenses/MIT) Copyright © 2009-present, AdmiralCloud AG, Mark Poepping
package/index.js ADDED
@@ -0,0 +1,19 @@
1
+ class ACError extends Error {
2
+ constructor(message, code, additionalInfo = {}) {
3
+ super(message)
4
+
5
+ if (Error.captureStackTrace) {
6
+ Error.captureStackTrace(this, ACError)
7
+ }
8
+ // info
9
+ this.code = code || -1
10
+ this.errorMessage = message
11
+ // show other properties of options object
12
+ if (Object.keys(additionalInfo).length) {
13
+ this.additionalInfo = additionalInfo
14
+ }
15
+ }
16
+ }
17
+
18
+
19
+ module.exports = ACError
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "ac-custom-error",
3
+ "version": "0.1.0",
4
+ "description": "Custom NodeJS error with error code and additional info",
5
+ "main": "index.js",
6
+ "repository": "https://github.com/AdmiralCloud/ac-custom-error",
7
+ "author": "Mark Poepping (www.admiralcloud.com)",
8
+ "license": "MIT",
9
+ "devDependencies": {
10
+ "ac-semantic-release": "^0.3.4",
11
+ "chai": "^4.3.7",
12
+ "eslint": "^8.32.0",
13
+ "mocha": "^10.2.0",
14
+ "nyc": "^15.1.0"
15
+ },
16
+ "scripts": {
17
+ "test": "mocha --reporter spec",
18
+ "coverage": "nyc yarn run test"
19
+ },
20
+ "engines": {
21
+ "node": ">=16.0.0"
22
+ }
23
+ }
package/test.js ADDED
@@ -0,0 +1,42 @@
1
+ const { expect } = require('chai')
2
+
3
+ const ACError = require('./index')
4
+
5
+ const errorFunction = ({ message, code, additionalInfo }) => {
6
+ throw new ACError(message, code, additionalInfo)
7
+ }
8
+
9
+
10
+ describe('Run tests', () => {
11
+
12
+ it('Check error code', () => {
13
+ let errorParams = { message: 'myError', code: 123 }
14
+ let error
15
+ try {
16
+ errorFunction(errorParams)
17
+ }
18
+ catch (err) {
19
+ error = err
20
+ }
21
+ expect(error).to.be.an('Error')
22
+ expect(error.message).to.equal(errorParams.message)
23
+ expect(error.code).to.equal(errorParams.code)
24
+ })
25
+
26
+ it('Check error code and additionalInfo', () => {
27
+ let errorParams = { message: 'myError', code: 123, additionalInfo: { id: 333 } }
28
+ let error
29
+ try {
30
+ errorFunction(errorParams)
31
+ }
32
+ catch (err) {
33
+ error = err
34
+ }
35
+ expect(error).to.be.an('Error')
36
+ expect(error.message).to.equal(errorParams.message)
37
+ expect(error.code).to.equal(errorParams.code)
38
+ expect(error.additionalInfo.id).to.equal(errorParams.additionalInfo.id)
39
+ })
40
+
41
+ })
42
+