Explorer
Node.js

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; } } ```

Custom Error Class

Medium
Create a `ValidationError` class that extends Error with a `field` property and `statusCode` of 400.
Editor
Loading Editor...
Evaluate code
Output:Click "Run" above to execute and verify your code here.
{"name":"ValidationError","message":"Invalid email","field":"email","statusCode":400,"isError":true}