Bummer! This is just a preview. You need to be signed in with an account to view the entire instruction.

Instruction

Return Validation Error Messages

If the errors array contains any elements (indicating that one of our validation rules failed) let's return a response with a 400 Bad Request HTTP status code along with the errors.

  1. In route.js, add the if statement shown below to the POST /api/users route handler:

    // Validate that we have a `name` value.
    if (!user.name) { ... }
    
    // Validate ...