0
0
Nginxdevops~5 mins

JSON error responses in Nginx - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Alocation
Bproxy_pass
Cerror_page
Dreturn
What Content-Type header should be set for JSON error responses?
Aapplication/json
Btext/html
Ctext/plain
Dapplication/xml
What is the main benefit of JSON error responses in APIs?
AThey are easier for humans to read
BThey improve network speed
CThey reduce server load
DThey allow clients to parse errors programmatically
Which HTTP status code is commonly used for 'Not Found' errors?
A200
B404
C301
D500
In nginx, how can you serve a JSON error response inline without a separate file?
AUsing 'return' with JSON string and setting Content-Type
BUsing 'proxy_pass' to a JSON server
CUsing 'rewrite' directive
DUsing 'listen' directive
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.