Handling validation errors
Using FlightSchedule
from the Creating custom validation methods section, we will go over how to handle validation errors when invoking the validate
, update
, and create
methods. Let’s presume that we called a createFlightSchedule
method that looks as follows:
const { ValidationError } = require('@sequelize/core'); // other imports and code... async function createFlightSchedule() { try { await FlightSchedule.create({ originAirport: 'JAX', destinationAirport: 'JFK', departureTime: '2030-01-01T00:00:00.000+00:00' }); } catch (err) { if (err instanceof ValidationError) { console.log(err.errors); } else { console.log...