canonical-ubuntu-qa team mailing list archive
-
canonical-ubuntu-qa team
-
Mailing list archive
-
Message #04869
[Merge] ~hyask/autopkgtest-cloud:skia/exceptions_improvements into autopkgtest-cloud:master
Skia has proposed merging ~hyask/autopkgtest-cloud:skia/exceptions_improvements into autopkgtest-cloud:master.
Requested reviews:
Canonical's Ubuntu QA (canonical-ubuntu-qa)
For more details, see:
https://code.launchpad.net/~hyask/autopkgtest-cloud/+git/autopkgtest-cloud/+merge/470025
Small exception handling improvement to avoid throwing 500 instead of 404.
--
Your team Canonical's Ubuntu QA is requested to review the proposed merge of ~hyask/autopkgtest-cloud:skia/exceptions_improvements into autopkgtest-cloud:master.
diff --git a/charms/focal/autopkgtest-web/webcontrol/browse.cgi b/charms/focal/autopkgtest-web/webcontrol/browse.cgi
index 3029f4f..6bca4d2 100755
--- a/charms/focal/autopkgtest-web/webcontrol/browse.cgi
+++ b/charms/focal/autopkgtest-web/webcontrol/browse.cgi
@@ -969,13 +969,17 @@ def statistics():
if __name__ == "__main__":
@app.errorhandler(Exception)
- def all_exception_handler(error):
+ def all_exception_handler(exception):
# If the exception doesn't have the exit_code method, it's not an expected
# exception defined in helpers/exceptions.py
try:
- exit_code = error.exit_code()
- except Exception:
- exit_code = 500
+ exit_code = exception.exit_code()
+ except AttributeError:
+ # werkzeug exceptions have a code, otherwise let's default to a generic 500
+ try:
+ exit_code = exception.code
+ except AttributeError:
+ exit_code = 500
# this can be simplified to the following after we move past Python 3.10
# traceback.print_exception(error)
@@ -983,7 +987,7 @@ if __name__ == "__main__":
traceback.print_exception(exc_type, exc_value, exc_traceback)
return render(
"browse-error.html",
- error=error,
+ error=exception,
tb=traceback.format_exception(exc_type, exc_value, exc_traceback),
exit_code=exit_code,
code=exit_code,