Complete the code to send a JSON error response with status 400.
res.status(400).json({ error: [1] });
Use a string message inside the error property to describe the error.
Complete the code to set the HTTP status to 404 before sending the error JSON.
res.[1](404).json({ error: "Not found" });
send instead of status to set the status code.set which is for headers.The status method sets the HTTP status code before sending the response.
Fix the error in the code to properly send a JSON error response with status 500.
res.status(500).[1]({ message: "Server error" });
send which may not set the content type correctly.write or end which are lower-level methods.Use json to send a JSON response. send can send strings or buffers but json formats the object as JSON.
Fill both blanks to create a middleware that sends a 401 error with a JSON message.
app.use((req, res) => { res.[1]([2]).json({ error: "Unauthorized" }); });send instead of status to set the status code.Use status to set the HTTP status code and 401 for unauthorized errors.
Fill all three blanks to send a 422 error with a JSON object containing code, message, and details.
res.[1]([2]).json({ code: [3], message: "Invalid data", details: "Missing fields" });
send instead of status.Use status to set the HTTP status code to 422. The code property in JSON should also be 422 as a number.