Recall & Review
beginner
What is the purpose of formatting error responses in Express?
Formatting error responses helps clients understand what went wrong by providing clear, consistent messages and status codes.
Click to reveal answer
beginner
Which HTTP status code is commonly used for a generic server error in Express?
The status code 500 is used for internal server errors indicating something went wrong on the server side.
Click to reveal answer
beginner
How can you send a JSON error response with a message and status code in Express?
Use res.status(code).json({ error: 'message' }) to send a JSON error with the right HTTP status.
Click to reveal answer
intermediate
Why should error responses include both a status code and a message?
Status codes tell the client the type of error, while messages explain details, making debugging easier.
Click to reveal answer
intermediate
What is a common pattern to handle errors globally in an Express app?
Use an error-handling middleware function with four arguments (err, req, res, next) to catch and format errors consistently.
Click to reveal answer
Which method sets the HTTP status code in an Express response?
✗ Incorrect
res.status() sets the HTTP status code before sending the response.
What is the correct way to send a JSON error message with status 404 in Express?
✗ Incorrect
res.status(404).json({ error: 'Not found' }) sets status and sends JSON error.
In Express, what does an error-handling middleware function require?
✗ Incorrect
Error middleware must have four parameters to catch errors properly.
Why is it important to send consistent error response formats?
✗ Incorrect
Consistent formats help clients understand and react to errors correctly.
Which status code indicates a client error due to bad input?
✗ Incorrect
400 means Bad Request, indicating client-side input errors.
Explain how to create a global error handler in Express and why it is useful.
Think about middleware that catches errors and sends a response.
You got /4 concepts.
Describe the key parts of a well-formatted error response in an Express app.
What does the client need to understand the error?
You got /4 concepts.