-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[allsearch-api] Error statuses in JSON format
This allows 400 and 500 JSON responses through from the application, and returns other errors in JSON format, rather than the standard "Something went wrong" html page. Closes #4396 For background information on why we'd like to offer JSON errors, see https://github.com/pulibrary/allsearch_api/blob/main/architecture-decisions/001_error_output.md
- Loading branch information
1 parent
2a957fe
commit 9cafb42
Showing
7 changed files
with
64 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
roles/nginxplus/files/conf/http/templates/errors-in-json-format.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# This error handling template is intended for applications | ||
# like allsearch-api, which attempt to respond in json for | ||
# all requests | ||
# | ||
# The application creates descriptive JSON for 400 and 500 | ||
# status codes, so those are not specifically handled here. | ||
# | ||
# More info at https://github.com/pulibrary/allsearch_api/blob/main/architecture-decisions/001_error_output.md | ||
|
||
error_page 401 402 404 405 406 407 408 409 411 412 413 414 415 416 417 418 421 422 423 424 426 428 431 451 501 502 503 504 505 506 507 508 510 511 /error.json; | ||
|
||
error_page 403 /forbidden.json; | ||
error_page 413 /too_large.json; | ||
error_page 429 /ratelimit.json; | ||
|
||
location = /error.json { | ||
ssi on; | ||
internal; | ||
root /var/local/www/default; | ||
} | ||
|
||
location = /forbidden.json { | ||
ssi on; | ||
internal; | ||
root /var/local/www/default; | ||
} | ||
|
||
location = /too_large.json { | ||
ssi on; | ||
internal; | ||
root /var/local/www/default; | ||
} | ||
|
||
location = /ratelimit.json { | ||
ssi on; | ||
internal; | ||
root /var/local/www/default; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"error": { | ||
"problem": "ERROR", | ||
"message": "We encountered an error." | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"error": { | ||
"problem": "FORBIDDEN", | ||
"message": "You are not allowed to access this. If you are attempting to reach a staging site, check if you are on VPN." | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"error": { | ||
"problem": "TOO_MANY_REQUESTS", | ||
"message": "You are making too many requests. Please find a way to accomplish your task without making so many requests." | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"error": { | ||
"problem": "CONTENT_TOO_LARGE", | ||
"message": "You are making a request that is too large for us to process. If you are in a browser, check your cookies to make sure you are not sending many large cookies at once." | ||
} | ||
} |