Recall & Review
beginner
What is the purpose of API error handling in Flask?
API error handling in Flask helps manage unexpected problems by sending clear, helpful error messages to users instead of crashing or showing confusing errors.
Click to reveal answer
beginner
How do you create a custom error response in Flask?
You create a custom error response by defining an error handler function with @app.errorhandler(error_code) decorator and returning a JSON response with a message and status code.
Click to reveal answer
beginner
What does the @app.errorhandler decorator do?
The @app.errorhandler decorator tells Flask to run a specific function when a certain error happens, like 404 Not Found or 500 Internal Server Error.
Click to reveal answer
beginner
Why should API error responses use JSON format?
API error responses use JSON so that client apps can easily read and understand the error details and handle them properly, keeping communication clear and consistent.
Click to reveal answer
beginner
What HTTP status code is commonly used for 'Resource Not Found' errors?
The HTTP status code 404 is used to indicate that the requested resource was not found on the server.
Click to reveal answer
Which Flask decorator is used to handle specific HTTP errors?
✗ Incorrect
The @app.errorhandler decorator is used to define functions that handle specific HTTP errors.
What should an API return when a requested item is not found?
✗ Incorrect
APIs should return HTTP 404 status with a JSON error message to clearly indicate the resource was not found.
Why is it important to handle errors in an API?
✗ Incorrect
Handling errors properly helps users and client apps understand what went wrong and how to fix it.
Which content type is best for API error responses?
✗ Incorrect
application/json is best because it allows clients to parse error details easily.
What does a 500 HTTP status code indicate?
✗ Incorrect
500 means the server encountered an unexpected condition that prevented it from fulfilling the request.
Explain how to create a custom error handler in Flask and why it is useful.
Think about how Flask knows what to do when an error happens.
You got /4 concepts.
Describe the importance of returning proper HTTP status codes and JSON error messages in API error handling.
Consider how apps talk to each other over the internet.
You got /4 concepts.