common-errors
Advanced tools
Comparing version
@@ -9,2 +9,3 @@ module.exports = { | ||
NotPermitted: require('./lib/notPermitted'), | ||
AuthenticationRequired: require('./lib/authenticationRequired'), | ||
middleware: { | ||
@@ -11,0 +12,0 @@ errorHandler: require('./lib/middleware/errorHandler'), |
@@ -27,2 +27,3 @@ module.exports = function errorHandler(err, req, res, next){ | ||
else if(err.name == "ValidationError") statusCode = 400; | ||
else if(err.name == "AuthenticationRequiredError") statusCode = 401; | ||
else if(err.name == "HttpStatusError") statusCode = err.statusCode; | ||
@@ -29,0 +30,0 @@ else statusCode = 500; |
@@ -5,3 +5,3 @@ { | ||
"description": "Common error classes and utility functions", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
@@ -16,2 +16,3 @@ node-errors | ||
* [NotPermittedError](#notpermitted) | ||
* [AuthenticationRequiredError](#authrequired) | ||
* [ValidationError](#validation) | ||
@@ -126,2 +127,19 @@ | ||
<a name="authrequired" /> | ||
### AuthenticationRequiredError | ||
Applicable when an operation requires authentication | ||
__Arguments__ | ||
new AuthenticationRequiredError(message) | ||
* message - any message | ||
```js | ||
throw new errors.AuthenticationRequiredError("Please provide authentication.") | ||
``` | ||
--------------------------------------- | ||
<a name="notpermitted" /> | ||
@@ -128,0 +146,0 @@ ### NotPermittedError |
17411
8.2%16
14.29%265
7.29%270
7.14%