mirror of
https://github.com/goldbergyoni/nodebestpractices.git
synced 2025-10-29 00:19:14 +08:00
ES6 Class Syntax refactor (#250)
* ES6 Class Syntax refactor * Capitalize Class name * Missing capitalisation in object
This commit is contained in:
@ -8,19 +8,21 @@ Distinguishing the following two error types will minimize your app downtime and
|
||||
|
||||
```javascript
|
||||
// marking an error object as operational
|
||||
var myError = new Error("How can I add new product when no value provided?");
|
||||
const myError = new Error("How can I add new product when no value provided?");
|
||||
myError.isOperational = true;
|
||||
|
||||
// or if you're using some centralized error factory (see other examples at the bullet "Use only the built-in Error object")
|
||||
function appError(commonType, description, isOperational) {
|
||||
class AppError {
|
||||
constructor (commonType, description, isOperational) {
|
||||
Error.call(this);
|
||||
Error.captureStackTrace(this);
|
||||
this.commonType = commonType;
|
||||
this.description = description;
|
||||
this.isOperational = isOperational;
|
||||
}
|
||||
};
|
||||
|
||||
throw new appError(errorManagement.commonErrors.InvalidInput, "Describe here what happened", true);
|
||||
throw new AppError(errorManagement.commonErrors.InvalidInput, "Describe here what happened", true);
|
||||
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user