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>
28 lines
1.1 KiB
Python
28 lines
1.1 KiB
Python
from typing import Any
|
||
|
||
from fastapi import status as status_code
|
||
from pydantic import BaseModel, Field
|
||
|
||
|
||
class BaseError(BaseModel):
|
||
"""Error response as defined in
|
||
https://datatracker.ietf.org/doc/html/rfc7807.
|
||
|
||
One difference is that the member "type" is not a URI
|
||
"""
|
||
|
||
type: str | None = Field(title="The name of the class of the error")
|
||
title: str | None = Field(
|
||
title="A short, human-readable summary of the problem that does not change from occurence to occurence",
|
||
)
|
||
detail: str | None = Field(
|
||
default=None, title="А human-readable explanation specific to this occurrence of the problem"
|
||
)
|
||
instance: Any | None = Field(default=None, title="Identifier for this specific occurrence of the problem")
|
||
|
||
|
||
class BaseResponse(BaseModel):
|
||
status: int = Field(..., title="Status code of request.", example=status_code.HTTP_200_OK) # type: ignore[call-arg]
|
||
error: dict[Any, Any] | BaseError | None = Field(default=None, title="Errors")
|
||
payload: Any | None = Field(default_factory=dict, title="Payload data.")
|