Skip to content

Commit 7244bd7

Browse files
authored
Merge pull request #115 from martin-kuba/json_error_messages
JSON ErrorDocuments for APIs
2 parents 1dabb38 + 8e0be53 commit 7244bd7

8 files changed

Lines changed: 49 additions & 12 deletions

File tree

templates/maintenance/401.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "https://{{ perun_api_hostname }}/maintenance/401.html",
3+
"status": 401,
4+
"title": "Unauthorized",
5+
"detail": "hint: provide 'Authorization:' header, contact {{ perun_email }} for help"
6+
}

templates/maintenance/403.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "https://{{ perun_api_hostname }}/maintenance/403.html",
3+
"status": 403,
4+
"title": "Forbidden",
5+
"detail": "hint: provide authentication prefix e.g. https://{{ perun_api_hostname }}/oauth/rpc/ contact {{ perun_email }} for help"
6+
}

templates/maintenance/404.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "https://{{ perun_api_hostname }}/maintenance/404.html",
3+
"status": 404,
4+
"title": "Not Found",
5+
"detail": "requested resource was not found, contact {{ perun_email }} for help"
6+
}

templates/maintenance/500.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "https://{{ perun_api_hostname }}/maintenance/500.html",
3+
"status": 500,
4+
"title": "Internal Server Error",
5+
"detail": "Server has encountered internal error. Please try again later or contact {{ perun_email }}"
6+
}

templates/maintenance/502.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"status": 502,
3+
"title": "Bad Gateway",
4+
"detail": "Web server cannot contact Perun RPC at the moment. Please try again later or contact {{ perun_email }}"
5+
}

templates/maintenance/503.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "https://{{ perun_api_hostname }}/maintenance/503.html",
3+
"status": 503,
4+
"title": "Service Unavailable",
5+
"detail": "Apache cannot contact Tomcat at the moment. Please try again later or contact {{ perun_email }}"
6+
}

templates/sites-enabled/perun-api-cert.conf.j2

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@
3232
Require all granted
3333
</Directory>
3434

35-
# GENERIC ERRORS
36-
ErrorDocument 401 /maintenance/401.html
37-
ErrorDocument 403 /maintenance/403.html
38-
ErrorDocument 404 /maintenance/404.html
39-
ErrorDocument 500 /maintenance/500.html
40-
ErrorDocument 503 /maintenance/503.html
35+
# GENERIC ERRORS (RFC 7807 JSON format)
36+
ErrorDocument 401 /maintenance/401.json
37+
ErrorDocument 403 /maintenance/403.json
38+
ErrorDocument 404 /maintenance/404.json
39+
ErrorDocument 500 /maintenance/500.json
40+
ErrorDocument 502 /maintenance/502.json
41+
ErrorDocument 503 /maintenance/503.json
4142

4243
RewriteEngine On
4344

templates/sites-enabled/perun-api.conf.j2

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@
3232
Require all granted
3333
</Directory>
3434

35-
# GENERIC ERRORS
36-
ErrorDocument 401 /maintenance/401.html
37-
ErrorDocument 403 /maintenance/403.html
38-
ErrorDocument 404 /maintenance/404.html
39-
ErrorDocument 500 /maintenance/500.html
40-
ErrorDocument 503 /maintenance/503.html
35+
# GENERIC ERRORS (RFC 7807 JSON format)
36+
ErrorDocument 401 /maintenance/401.json
37+
ErrorDocument 403 /maintenance/403.json
38+
ErrorDocument 404 /maintenance/404.json
39+
ErrorDocument 500 /maintenance/500.json
40+
ErrorDocument 502 /maintenance/502.json
41+
ErrorDocument 503 /maintenance/503.json
4142

4243
RewriteEngine On
4344

0 commit comments

Comments
 (0)