X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=o2common%2Fviews%2Froute_exception.py;fp=o2common%2Fviews%2Froute_exception.py;h=b66a66322b1eaa5110ccdc3eb7345ec98d043fad;hb=ded3e3d01ef6447b5e27a2be03227edd4b5a352b;hp=ccb439b8572e1fe226cb80d598c00f37aed99b70;hpb=4cf8adc69fbc8f44cdd6d978cebed0119bc5a216;p=pti%2Fo2.git diff --git a/o2common/views/route_exception.py b/o2common/views/route_exception.py index ccb439b..b66a663 100644 --- a/o2common/views/route_exception.py +++ b/o2common/views/route_exception.py @@ -18,6 +18,7 @@ from werkzeug.exceptions import ( MethodNotAllowed, NotFound, InternalServerError, + HTTPException, ) @@ -61,6 +62,19 @@ class ProblemDetails(): def configure_exception(app): + @app.errorhandler(HTTPException) + def default_error_handler(error): + '''Default error handler''' + status_code = getattr(error, 'code', 500) + problem = ProblemDetails(status_code, str(error)) + return problem.serialize(), status_code + + @app.errorhandler(NotFound) + def handle_notfound(error): + '''notfound handler''' + problem = ProblemDetails(404, str(error)) + return problem.serialize(), 404 + @app.errorhandler(BadRequestException) def handle_badrequest_exception(error): '''Return a custom message and 400 status code'''