Generating validation error messages

When our object fails validation, we should generate the same human-readable error messages as we did before. To do this, we must process the errors stored at ajvValidate.errors, and use them to generate human-readable messages. Thus, create a new module at src/validators/errors/messages.js, and copy the following message generator:

function generateValidationErrorMessage(errors) {  const error = errors[0];  if (error.dataPath.indexOf('.profile') === 0) {    return 'The profile provided is invalid.';  }  if (error.keyword === 'required') {    return 'Payload must contain at least the email and password fields';  }  if (error.keyword === 'type') {    return 'The email and password fields must be of type string';  } if ...

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.