Creating the ValidationError interface

Create a new file at src/validators/errors/validation-error.js and add a class definition for ValidationError:

class ValidationError extends Error {  constructor(...params) {    super(...params);    if (Error.captureStackTrace) {      Error.captureStackTrace(this, ValidationError);    }  }}export default ValidationError;

The preceding code extends the Error class to create its own class. We need to do this in order to distinguish between validation errors (which should return a 400 response) and errors in our code (which should return a 500 response).

Get Building Enterprise JavaScript Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.