@venncity/errors
Advanced tools
Comparing version 1.3.0 to 1.4.0
@@ -6,2 +6,13 @@ # Change Log | ||
# [1.4.0](https://github.com/venn-city/npm-shelf/compare/@venncity/errors@1.3.0...@venncity/errors@1.4.0) (2019-10-22) | ||
### Features | ||
* **errors:** add logLevel on errors ([c6f0700](https://github.com/venn-city/npm-shelf/commit/c6f0700)) | ||
# [1.3.0](https://github.com/venn-city/npm-shelf/compare/@venncity/errors@1.2.0...@venncity/errors@1.3.0) (2019-09-03) | ||
@@ -8,0 +19,0 @@ |
{ | ||
"name": "@venncity/errors", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"author": "Venn Engineering", | ||
@@ -29,3 +29,3 @@ "main": "src/index.js", | ||
}, | ||
"gitHead": "b0e5430d37fc53dd9a6b799928aec2c01d736aaf" | ||
"gitHead": "a34d45d4f2b77c730b9e98c02bceaba155aa2386" | ||
} |
@@ -8,3 +8,4 @@ const { | ||
ThrottlingError, | ||
VError | ||
VError, | ||
SUPPORTED_LOG_LEVELS: { WARN, ERROR } | ||
} = require('./errors'); | ||
@@ -17,3 +18,4 @@ | ||
isVennError: true, | ||
message: 'VennUnknownError: nested' | ||
message: 'VennUnknownError: nested', | ||
logLevel: ERROR | ||
}); | ||
@@ -28,3 +30,4 @@ expect(VError.info(unknownError)).toEqual({ clientVisible: false, statusCode: 500 }); | ||
isVennError: true, | ||
message: 'msg: nested' | ||
message: 'msg: nested', | ||
logLevel: ERROR | ||
}); | ||
@@ -39,3 +42,4 @@ expect(VError.info(forbiddenError)).toEqual({ clientVisible: false, statusCode: 403 }); | ||
isVennError: true, | ||
message: 'msg: nested' | ||
message: 'msg: nested', | ||
logLevel: ERROR | ||
}); | ||
@@ -50,3 +54,4 @@ expect(VError.info(throttlingError)).toEqual({ clientVisible: false, statusCode: 429 }); | ||
isVennError: true, | ||
message: 'msg: nested' | ||
message: 'msg: nested', | ||
logLevel: ERROR | ||
}); | ||
@@ -61,3 +66,4 @@ expect(VError.info(vennError)).toEqual({ clientVisible: false, statusCode: 300 }); | ||
isVennError: true, | ||
message: 'serverError: nested' | ||
message: 'serverError: nested', | ||
logLevel: ERROR | ||
}); | ||
@@ -69,10 +75,24 @@ expect(VError.info(serverDataValidationError)).toEqual({ clientVisible: false, statusCode: 500 }); | ||
test('verify ClientDataValidationError to contain all required fields', () => { | ||
const clientDataValidationError = new ClientDataValidationError({ cause: new Error('nested'), message: 'clientError' }); | ||
const clientDataValidationErrorWarn = new ClientDataValidationError({ cause: new Error('nested'), | ||
message: 'clientError', | ||
logLevel: WARN }); | ||
const clientDataValidationError = new ClientDataValidationError({ cause: new Error('nested'), | ||
message: 'clientError' }); | ||
expect(clientDataValidationErrorWarn).toMatchObject({ | ||
isVennError: true, | ||
message: 'clientError: nested', | ||
logLevel: WARN | ||
}); | ||
expect(clientDataValidationError).toMatchObject({ | ||
isVennError: true, | ||
message: 'clientError: nested' | ||
message: 'clientError: nested', | ||
logLevel: ERROR | ||
}); | ||
expect(VError.info(clientDataValidationError)).toEqual({ clientVisible: true, statusCode: 400 }); | ||
expect(VError.cause(clientDataValidationError)).toHaveProperty('message', 'nested'); | ||
expect(VError.info(clientDataValidationErrorWarn)).toEqual({ clientVisible: true, statusCode: 400 }); | ||
expect(VError.cause(clientDataValidationErrorWarn)).toHaveProperty('message', 'nested'); | ||
}); | ||
}); |
@@ -9,5 +9,11 @@ const { VError } = require('verror'); | ||
const VENN_CLIENT_DATA_VALIDATION_ERROR = 'VennClientDataValidationError'; | ||
const SUPPORTED_LOG_LEVELS = { | ||
ERROR: 'error', | ||
WARN: 'warn', | ||
INFO: 'info' | ||
}; | ||
class VennError extends VError { | ||
constructor({ cause, message, clientVisible = false, statusCode = 500, name = VENN_ERROR }) { | ||
constructor({ cause, message, clientVisible = false, statusCode = 500, name = VENN_ERROR, logLevel = SUPPORTED_LOG_LEVELS.ERROR }) { | ||
super({ | ||
@@ -22,2 +28,3 @@ name, | ||
this.isVennError = true; | ||
this.logLevel = logLevel; | ||
} | ||
@@ -33,4 +40,4 @@ } | ||
class DataValidationError extends VennError { | ||
constructor({ cause, message, clientVisible, statusCode, name }) { | ||
super({ cause, message, clientVisible, statusCode, name }); | ||
constructor({ cause, message, clientVisible, statusCode, name, logLevel }) { | ||
super({ cause, message, clientVisible, statusCode, name, logLevel }); | ||
this.isDataValidationError = true; | ||
@@ -47,4 +54,4 @@ } | ||
class ClientDataValidationError extends DataValidationError { | ||
constructor({ cause, message, clientVisible = true }) { | ||
super({ cause, message, clientVisible, statusCode: 400, name: VENN_CLIENT_DATA_VALIDATION_ERROR }); | ||
constructor({ cause, message, clientVisible = true, logLevel }) { | ||
super({ cause, message, clientVisible, statusCode: 400, name: VENN_CLIENT_DATA_VALIDATION_ERROR, logLevel }); | ||
} | ||
@@ -89,3 +96,4 @@ } | ||
VENN_CLIENT_DATA_VALIDATION_ERROR | ||
} | ||
}, | ||
SUPPORTED_LOG_LEVELS | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11646
243