Complete the code to set the content type to JSON in the error response.
error_page 404 /404.json; location = /404.json { default_type [1]; return 404 '{"error": "Not Found"}'; }
The default_type directive sets the MIME type. For JSON responses, use application/json.
Complete the code to return a 500 error with a JSON message.
location /500.json { default_type application/json; return [1] '{"error": "Internal Server Error"}'; }
The return directive sends the HTTP status code. For server errors, use 500.
Fix the error in the JSON error response to properly escape quotes.
location /403.json { default_type application/json; return 403 '{"error": [1]Forbidden[2]'; }
Inside single quotes, double quotes must be escaped with a backslash to form valid JSON.
Fill both blanks to create a JSON error response with a custom message and status code.
location /custom_error.json {
default_type [1];
return [2] '{"error": "Custom Error"}';
}Set default_type to application/json and return status code 404 for not found errors.
Fill all three blanks to define a JSON error response with a dynamic error message and status code.
location /error.json {
default_type [1];
set $err_msg '[2]';
return [3] '{"error": "$err_msg"}';
}Set content type to application/json, error message to 'Forbidden', and status code to 403.