Challenge - 5 Problems
JSON Error Response Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of this nginx error response configuration?
Given this nginx configuration snippet for JSON error response, what will be the exact JSON output when a 404 error occurs?
Nginx
error_page 404 = /custom_404.json; location = /custom_404.json { default_type application/json; return 404 '{"error": "Not Found", "code": 404}'; }
Attempts:
2 left
💡 Hint
Look at the return directive and the content type set.
✗ Incorrect
The configuration sets the content type to application/json and returns a JSON string with error and code fields for 404 errors.
❓ Configuration
intermediate2:00remaining
Which configuration snippet correctly returns a JSON error for 500 errors?
Select the nginx configuration snippet that correctly returns a JSON error response with status 500 and message "Internal Server Error".
Attempts:
2 left
💡 Hint
Check the status code in the return directive and the content type.
✗ Incorrect
Option C correctly sets the error_page, location with exact match, content type application/json, and returns status 500 with the correct JSON message.
❓ Troubleshoot
advanced2:00remaining
Why does this nginx JSON error response return HTML instead of JSON?
You configured nginx as below to return JSON on 403 errors, but the client receives HTML instead. What is the most likely cause?
Nginx
error_page 403 = /403.json; location = /403.json { return 403 '{"error": "Forbidden", "code": 403}'; }
Attempts:
2 left
💡 Hint
Check what content type nginx sends by default if not specified.
✗ Incorrect
Without default_type application/json, nginx defaults to text/html, so the client receives HTML instead of JSON.
✅ Best Practice
advanced2:00remaining
What is the best practice to serve consistent JSON error responses in nginx?
Which approach ensures all error responses (e.g., 400, 403, 404, 500) return JSON with proper status and message?
Attempts:
2 left
💡 Hint
Think about how to customize each error code's message and status properly.
✗ Incorrect
Separate error_page and location blocks allow precise control of status codes and JSON messages per error, ensuring consistency.
🧠 Conceptual
expert2:00remaining
What happens if you omit the '=' sign in error_page directive for JSON error responses?
Consider this directive: error_page 404 /404.json; without '=' sign. What is the effect on the HTTP status code and response body?
Attempts:
2 left
💡 Hint
Understand the difference between internal redirect with and without '=' in error_page.
✗ Incorrect
Without '=', nginx internally redirects to the URI but preserves the original error status code, so client sees 404 with content from /404.json.