Recall & Review
beginner
What is a custom error class in Express?A custom error class is a user-defined class that extends the built-in Error class to create specific error types with custom properties or messages, helping to handle errors more clearly in Express apps.Click to reveal answer
beginner
How do you create a basic custom error class in Express?You create a class that extends Error, call super(message) in the constructor, and optionally add properties like statusCode to represent HTTP error codes.Click to reveal answer
intermediate
Why add a statusCode property to a custom error class in Express?Adding statusCode helps middleware know which HTTP status to send in the response, making error responses clear and consistent.
Click to reveal answer
intermediate
What is the benefit of using custom error classes over plain Error objects in Express?
Custom error classes let you distinguish error types easily, add extra info, and handle different errors in specific ways in middleware.Click to reveal answer
beginner
Show a simple example of a custom NotFoundError class in Express.class NotFoundError extends Error {
constructor(message = 'Not Found') {
super(message);
this.name = 'NotFoundError';
this.statusCode = 404;
}
}Click to reveal answer
What must a custom error class extend in Express?
✗ Incorrect
Custom error classes extend the built-in Error class to inherit error behavior.
Why include a statusCode property in a custom error?
✗ Incorrect
statusCode helps middleware send the right HTTP status code in the response.
Which method is called inside the constructor of a custom error class?
✗ Incorrect
super(message) calls the parent Error constructor with the error message.
What is a key advantage of custom error classes in Express?
✗ Incorrect
Custom errors let you handle different errors in tailored ways.
Which property usually holds the error message in a custom error?
✗ Incorrect
The message property contains the error description.
Explain how to create and use a custom error class in Express.
Think about how errors flow from route to middleware.
You got /5 concepts.
Describe why custom error classes improve error handling in Express applications.
Consider how different errors need different responses.
You got /5 concepts.