Create a `ValidationError` class that extends Error with a `field` property and `statusCode` of 400.
Problem Statement
Create a `ValidationError` class that extends Error with a `field` property and `statusCode` of 400.
Complexity
Time Complexity: -
Space Complexity: -
Hints
š” Hint 1:
Extend the Error class using class ValidationError extends Error.
š” Hint 2:
Call super(message) in the constructor.
š” Hint 3:
Set this.name, this.field, and this.statusCode in the constructor.
ā
Solution:
```javascript
class ValidationError extends Error {
constructor(message, field) {
super(message);
this.name = "ValidationError";
this.field = field;
this.statusCode = 400;
}
}
```