diff --git a/Makefile b/Makefile index a866b3a..107307e 100644 --- a/Makefile +++ b/Makefile @@ -38,6 +38,9 @@ clean: test: image $(DOCKER) run --rm -p 80:80 -p 443:443 -e DEBUG=1 $(IMAGE_NAME)/$(IMAGE_TAG) +test-release: image + $(DOCKER) run --rm -p 80:80 -p 443:443 $(IMAGE_NAME)/$(IMAGE_TAG) + test-bash: image $(DOCKER) run --rm -p 80:80 -p 443:443 -e DEBUG=1 -it $(IMAGE_NAME)/$(IMAGE_TAG) bash diff --git a/image/src/backend/router.py b/image/src/backend/router.py index b4ffff2..3c3a31d 100644 --- a/image/src/backend/router.py +++ b/image/src/backend/router.py @@ -1,8 +1,7 @@ import os -import json import inspect import logging -import contextlib +import traceback # Import typing utilities from typing import Union @@ -10,7 +9,7 @@ # Import starlette utilities from starlette.routing import Route, WebSocketRoute from starlette.requests import Request -from starlette.responses import Response, JSONResponse +from starlette.responses import Response, JSONResponse, PlainTextResponse from starlette.websockets import WebSocket from starlette.applications import Starlette @@ -237,5 +236,11 @@ def initialize(): # Set the new logging formatter handler.setFormatter(formatter) + # Create exception handler + exception_handlers = { + # When any exception occurs, return an exception string + Exception: lambda request, exception: PlainTextResponse(str(exception), 500) + } + # Initialize the starlette application - return Starlette(debug=DEBUG, routes=router.routes) + return Starlette(debug=DEBUG, routes=router.routes, exception_handlers=exception_handlers)