diff --git a/app/libs/base_handler.py b/app/libs/base_handler.py index edb8745..5ecbdc0 100644 --- a/app/libs/base_handler.py +++ b/app/libs/base_handler.py @@ -20,7 +20,7 @@ async def handle(self, context: Context): except Exception as e: _exception_handler: "Handler" = ExceptionHandler() # Extract the stack trace and log the exception - return await _exception_handler.handle(context, e) + return await _exception_handler.handle(self._next_handler, context, e) class DefaultCompletionHandler(Handler): @@ -51,11 +51,11 @@ async def handle(self, context: Context): class ExceptionHandler(Handler): - async def handle(self, context: Context, exception: Exception): - print(f"Error processing the request: {exception}") - print(traceback.format_exc()) + async def handle(self, handler: Handler, context: Context, exception: Exception): + print(f"Error processing the request: {str(handler.__class__) } - {exception}") + # print(traceback.format_exc()) return JSONResponse( - content={"error": "An unexpected error occurred. " + str(exception)}, + content={"error": "An unexpected error occurred, within handler " + str(handler.__class__) + " : " + str(exception)}, status_code=500, ) diff --git a/app/libs/tools_handler.py b/app/libs/tools_handler.py index 7d787a6..9703861 100644 --- a/app/libs/tools_handler.py +++ b/app/libs/tools_handler.py @@ -228,10 +228,10 @@ async def handle(self, context: Context): return JSONResponse(content=context.response, status_code=200) except Exception as e: # Log the exception or handle it as needed - print(e) - context.response = { - "error": "An error occurred processing the tool response" - } - return JSONResponse(content=context.response, status_code=500) + # context.response = { + # "error": "An error occurred processing the tool response" + # } + # return JSONResponse(content=context.response, status_code=500) + raise e return await super().handle(context)