@defra/bng-errors-lib 0.0.1
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 +3 -0
- package/__tests__/coordinate-system-validation-error-spec.js +17 -0
- package/__tests__/threat-screening-error-spec.js +13 -0
- package/__tests__/upload-type-validation-error-spec.js +17 -0
- package/__tests__/validation-error-spec.js +15 -0
- package/package.json +19 -0
- package/src/coordinate-system-validation-error.js +10 -0
- package/src/errors.js +6 -0
- package/src/threat-screening-error.js +8 -0
- package/src/upload-type-validation-error.js +10 -0
- package/src/validation-error.js +8 -0
package/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { CoordinateSystemValidationError } from '../src/errors.js'
|
|
2
|
+
|
|
3
|
+
const authorityKey = 'mock authority key'
|
|
4
|
+
const errorCode = 'mock error code'
|
|
5
|
+
const errorMessage = 'mock error message'
|
|
6
|
+
|
|
7
|
+
describe('Coordinate system validation errors', () => {
|
|
8
|
+
it('should supplement a standard Error with an authority key and error code', async () => {
|
|
9
|
+
try {
|
|
10
|
+
throw new CoordinateSystemValidationError(authorityKey, errorCode, errorMessage)
|
|
11
|
+
} catch (err) {
|
|
12
|
+
expect(err.authorityKey).toBe(authorityKey)
|
|
13
|
+
expect(err.code).toBe(errorCode)
|
|
14
|
+
expect(err.message).toBe(errorMessage)
|
|
15
|
+
}
|
|
16
|
+
})
|
|
17
|
+
})
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ThreatScreeningError } from '../src/errors.js'
|
|
2
|
+
|
|
3
|
+
const threatScreeningDetails = {}
|
|
4
|
+
|
|
5
|
+
describe('Threat screening errors', () => {
|
|
6
|
+
it('should supplement a standard Error with threat screening failure details', async () => {
|
|
7
|
+
try {
|
|
8
|
+
throw new ThreatScreeningError(threatScreeningDetails)
|
|
9
|
+
} catch (err) {
|
|
10
|
+
expect(err.threatScreeningDetails).toStrictEqual(threatScreeningDetails)
|
|
11
|
+
}
|
|
12
|
+
})
|
|
13
|
+
})
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { UploadTypeValidationError } from '../src/errors.js'
|
|
2
|
+
|
|
3
|
+
const uploadType = 'mock upload type'
|
|
4
|
+
const errorCode = 'mock error code'
|
|
5
|
+
const errorMessage = 'mock error message'
|
|
6
|
+
|
|
7
|
+
describe('Upload type validation errors', () => {
|
|
8
|
+
it('should supplement a standard Error with an upload type and error code', async () => {
|
|
9
|
+
try {
|
|
10
|
+
throw new UploadTypeValidationError(uploadType, errorCode, errorMessage)
|
|
11
|
+
} catch (err) {
|
|
12
|
+
expect(err.uploadType).toBe(uploadType)
|
|
13
|
+
expect(err.code).toBe(errorCode)
|
|
14
|
+
expect(err.message).toBe(errorMessage)
|
|
15
|
+
}
|
|
16
|
+
})
|
|
17
|
+
})
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ValidationError } from '../src/errors.js'
|
|
2
|
+
|
|
3
|
+
const errorCode = 'mock error code'
|
|
4
|
+
const errorMessage = 'mock error message'
|
|
5
|
+
|
|
6
|
+
describe('Validation errors', () => {
|
|
7
|
+
it('should supplement a standard Error with an error code', async () => {
|
|
8
|
+
try {
|
|
9
|
+
throw new ValidationError(errorCode, errorMessage)
|
|
10
|
+
} catch (err) {
|
|
11
|
+
expect(err.code).toBe(errorCode)
|
|
12
|
+
expect(err.message).toBe(errorMessage)
|
|
13
|
+
}
|
|
14
|
+
})
|
|
15
|
+
})
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@defra/bng-errors-lib",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"private": false,
|
|
6
|
+
"description": "Custom errors for Biodiversity Net Gain",
|
|
7
|
+
"main": "src/errors.js",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"test": "echo \\\"Error: run tests from root\\\" && exit 1"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/DEFRA/biodiversity-net-gain-service/errors-lib",
|
|
14
|
+
"directory": "errors-lib"
|
|
15
|
+
},
|
|
16
|
+
"author": "Department for Environment, Food and Rural Affairs <https://www.gov.uk/government/organisations/department-for-environment-food-rural-affairs>",
|
|
17
|
+
"license": "OGL-UK-3.0",
|
|
18
|
+
"gitHead": "c9754436d12d2e124d9a5733dd440cb0bfdd9098"
|
|
19
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import ValidationError from './validation-error.js'
|
|
2
|
+
|
|
3
|
+
// Adapted from https://medium.com/@xjamundx/custom-javascript-errors-in-es6-aa891b173f87
|
|
4
|
+
export default class CoordinateSystemValidationError extends ValidationError {
|
|
5
|
+
constructor (authorityKey, code, ...args) {
|
|
6
|
+
super(code, ...args)
|
|
7
|
+
this.authorityKey = authorityKey
|
|
8
|
+
Error.captureStackTrace(this, CoordinateSystemValidationError)
|
|
9
|
+
}
|
|
10
|
+
}
|
package/src/errors.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import CoordinateSystemValidationError from './coordinate-system-validation-error.js'
|
|
2
|
+
import ThreatScreeningError from './threat-screening-error.js'
|
|
3
|
+
import UploadTypeValidationError from './upload-type-validation-error.js'
|
|
4
|
+
import ValidationError from './validation-error.js'
|
|
5
|
+
|
|
6
|
+
export { CoordinateSystemValidationError, ThreatScreeningError, UploadTypeValidationError, ValidationError }
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Adapted from https://medium.com/@xjamundx/custom-javascript-errors-in-es6-aa891b173f87
|
|
2
|
+
export default class ThreatScreeningError extends Error {
|
|
3
|
+
constructor (threatScreeningDetails, ...args) {
|
|
4
|
+
super(...args)
|
|
5
|
+
this.threatScreeningDetails = threatScreeningDetails
|
|
6
|
+
Error.captureStackTrace(this, ThreatScreeningError)
|
|
7
|
+
}
|
|
8
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import ValidationError from './validation-error.js'
|
|
2
|
+
|
|
3
|
+
// Adapted from https://medium.com/@xjamundx/custom-javascript-errors-in-es6-aa891b173f87
|
|
4
|
+
export default class UploadTypeValidationError extends ValidationError {
|
|
5
|
+
constructor (uploadType, code, ...args) {
|
|
6
|
+
super(code, ...args)
|
|
7
|
+
this.uploadType = uploadType
|
|
8
|
+
Error.captureStackTrace(this, UploadTypeValidationError)
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Adapted from https://medium.com/@xjamundx/custom-javascript-errors-in-es6-aa891b173f87
|
|
2
|
+
export default class ValidationError extends Error {
|
|
3
|
+
constructor (code, ...args) {
|
|
4
|
+
super(...args)
|
|
5
|
+
this.code = code
|
|
6
|
+
Error.captureStackTrace(this, ValidationError)
|
|
7
|
+
}
|
|
8
|
+
}
|