Recall & Review
beginner
What is a JSON error response in the context of nginx?
A JSON error response is a structured message sent by nginx to the client when an error occurs, formatted in JSON to make it easy for applications to understand and handle the error.
Click to reveal answer
intermediate
How do you configure nginx to return a JSON error response?
You configure nginx to return JSON error responses by using the 'error_page' directive to specify a custom error page and then serving a JSON file or inline JSON content with the correct 'Content-Type: application/json' header.
Click to reveal answer
beginner
What HTTP header must be set to indicate a JSON error response?
The HTTP header 'Content-Type: application/json' must be set to indicate that the response body contains JSON data.
Click to reveal answer
beginner
Example of a simple JSON error response body?
{"error": {"code": 404, "message": "Not Found"}}
Click to reveal answer
intermediate
Why use JSON error responses instead of plain text in APIs?
JSON error responses allow clients to easily parse and handle errors programmatically, improving automation and user experience compared to plain text messages.
Click to reveal answer
Which nginx directive is used to specify a custom error page?
✗ Incorrect
The 'error_page' directive tells nginx which page or response to serve when a specific error occurs.
What Content-Type header should be set for JSON error responses?
✗ Incorrect
The 'application/json' header indicates the response body is JSON formatted.
What is the main benefit of JSON error responses in APIs?
✗ Incorrect
JSON error responses let client programs understand and react to errors automatically.
Which HTTP status code is commonly used for 'Not Found' errors?
✗ Incorrect
404 means the requested resource was not found on the server.
In nginx, how can you serve a JSON error response inline without a separate file?
✗ Incorrect
You can use 'return' with a status code and JSON string, plus 'add_header' to set Content-Type.
Explain how to configure nginx to return a JSON error response for a 404 error.
Think about how nginx handles error pages and headers.
You got /3 concepts.
Why is it important to set the Content-Type header correctly when returning JSON error responses?
Consider how clients read and use the response data.
You got /3 concepts.