Merge branch 'feature/error_pages' into 'master'
Improved webservice error handling See merge request cara/cara!157
This commit is contained in:
commit
ce6b4a4420
3 changed files with 48 additions and 1 deletions
|
|
@ -66,10 +66,20 @@ http {
|
|||
return 302 /auth/login;
|
||||
}
|
||||
|
||||
location @proxy_404_error_handler {
|
||||
# Pass the request on to the webservice. Most likely the URI won't
|
||||
# exist so we get a 404 from that service instead (good as the 404
|
||||
# pages are consistent).
|
||||
proxy_pass http://cara-webservice:8080/$request_uri;
|
||||
}
|
||||
|
||||
location /voila-server/ {
|
||||
proxy_intercept_errors on;
|
||||
|
||||
# Anything under voila-server or expert-app is authenticated.
|
||||
auth_request /auth/probe;
|
||||
error_page 401 = @error401;
|
||||
error_page 404 = @proxy_404_error_handler;
|
||||
|
||||
# cara-app is the name of the voila server in each of docker-compose,
|
||||
# test-cara.web.cern.ch and cara.web.cern.ch.
|
||||
|
|
|
|||
2
app.sh
2
app.sh
|
|
@ -1,6 +1,6 @@
|
|||
if [[ "$APP_NAME" == "cara-webservice" ]]; then
|
||||
echo "Starting the cara webservice"
|
||||
python -m cara.apps.calculator
|
||||
python -m cara.apps.calculator --no-debug
|
||||
elif [[ "$APP_NAME" == "cara-voila" ]]; then
|
||||
echo "Starting the voila service"
|
||||
voila app/ --port=8080 --no-browser --base_url=/voila-server/ --Voila.tornado_settings="{'allow_origin': '*'}"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
import datetime
|
||||
import html
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import traceback
|
||||
import uuid
|
||||
|
||||
import jinja2
|
||||
from tornado.web import Application, RequestHandler, StaticFileHandler
|
||||
|
|
@ -38,6 +41,39 @@ class BaseRequestHandler(RequestHandler):
|
|||
else:
|
||||
self.current_user = AnonymousUser()
|
||||
|
||||
def write_error(self, status_code: int, **kwargs) -> None:
|
||||
template = self.settings["template_environment"].get_template(
|
||||
"page.html.j2")
|
||||
|
||||
error_id = uuid.uuid4()
|
||||
contents = (
|
||||
f'Unfortunately an error occurred when processing your request. '
|
||||
f'Please let us know about this issue with as much detail as possible at '
|
||||
f'<a href="mailto:CARA-dev@cern.ch">CARA-dev@cern.ch</a>, reporting status '
|
||||
f'code {status_code}, the error id of "{error_id}" and the time of the '
|
||||
f'request ({datetime.datetime.utcnow()}).<br><br><br><br>'
|
||||
)
|
||||
# Print the error to the log (and not to the browser!)
|
||||
if "exc_info" in kwargs:
|
||||
print(f"ERROR UUID {error_id}")
|
||||
print(traceback.format_exc())
|
||||
self.finish(template.render(
|
||||
user=self.current_user,
|
||||
contents=contents
|
||||
))
|
||||
|
||||
|
||||
class Missing404Handler(BaseRequestHandler):
|
||||
async def prepare(self):
|
||||
await super().prepare()
|
||||
self.set_status(404)
|
||||
template = self.settings["template_environment"].get_template(
|
||||
"page.html.j2")
|
||||
self.finish(template.render(
|
||||
user=self.current_user,
|
||||
contents='Unfortunately the page you were looking for does not exist.<br><br><br><br>'
|
||||
))
|
||||
|
||||
|
||||
class ConcentrationModel(BaseRequestHandler):
|
||||
def post(self):
|
||||
|
|
@ -128,6 +164,7 @@ def make_app(debug=False, prefix='/calculator'):
|
|||
urls,
|
||||
debug=debug,
|
||||
template_environment=template_environment,
|
||||
default_handler_class=Missing404Handler,
|
||||
xsrf_cookies=True,
|
||||
# COOKIE_SECRET being undefined will result in no login information being
|
||||
# presented to the user.
|
||||
|
|
|
|||
Loading…
Reference in a new issue