mirror of
https://github.com/goldbergyoni/nodebestpractices.git
synced 2025-10-31 01:28:30 +08:00
Merge pull request #207 from Max101/patch-1
Constructor function in error should be uppercase
This commit is contained in:
@ -36,20 +36,20 @@ if(!productToAdd)
|
|||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// centralized error object that derives from Node’s Error
|
// centralized error object that derives from Node’s Error
|
||||||
function appError(name, httpCode, description, isOperational) {
|
function AppError(name, httpCode, description, isOperational) {
|
||||||
Error.call(this);
|
Error.call(this);
|
||||||
Error.captureStackTrace(this);
|
Error.captureStackTrace(this);
|
||||||
this.name = name;
|
this.name = name;
|
||||||
//...other properties assigned here
|
//...other properties assigned here
|
||||||
};
|
};
|
||||||
|
|
||||||
appError.prototype.__proto__ = Error.prototype;
|
AppError.prototype.__proto__ = Error.prototype;
|
||||||
|
|
||||||
module.exports.appError = appError;
|
module.exports.AppError = AppError;
|
||||||
|
|
||||||
// client throwing an exception
|
// client throwing an exception
|
||||||
if(user == null)
|
if(user == null)
|
||||||
throw new appError(commonErrors.resourceNotFound, commonHTTPErrors.notFound, "further explanation", true)
|
throw new AppError(commonErrors.resourceNotFound, commonHTTPErrors.notFound, "further explanation", true)
|
||||||
```
|
```
|
||||||
|
|
||||||
### Blog Quote: "I don’t see the value in having lots of different types"
|
### Blog Quote: "I don’t see the value in having lots of different types"
|
||||||
|
|||||||
Reference in New Issue
Block a user