mirror of
https://github.com/Balshgit/gpt_chat_bot.git
synced 2025-09-11 22:30:41 +03:00
* try to add exception handler * improve server error test * fix lint * add build_uri util * fix header file path --------- Co-authored-by: Dmitry Afanasyev <afanasiev@litres.ru>
35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
from fastapi.responses import ORJSONResponse
|
|
from starlette.requests import Request
|
|
|
|
from api.base_schemas import BaseError, BaseResponse
|
|
|
|
|
|
class BaseAPIException(Exception):
|
|
pass
|
|
|
|
|
|
class InternalServerError(BaseError):
|
|
pass
|
|
|
|
|
|
class InternalServerErrorResponse(BaseResponse):
|
|
error: InternalServerError
|
|
|
|
class Config:
|
|
json_schema_extra = {
|
|
"example": {
|
|
"status": 500,
|
|
"error": {
|
|
"type": "InternalServerError",
|
|
"title": "Server encountered an unexpected error that prevented it from fulfilling the request",
|
|
"detail": "error when adding send message",
|
|
},
|
|
},
|
|
}
|
|
|
|
|
|
async def internal_server_error_handler(_request: Request, _exception: Exception) -> ORJSONResponse:
|
|
error = InternalServerError(title="Something went wrong!", type="InternalServerError")
|
|
response = InternalServerErrorResponse(status=500, error=error).model_dump(exclude_unset=True)
|
|
return ORJSONResponse(status_code=500, content=response)
|