add api exception handler (#74)

* 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>
This commit is contained in:
Dmitry Afanasyev
2023-12-30 23:50:59 +03:00
committed by GitHub
parent d1ae7f2281
commit bf7a5520dc
10 changed files with 171 additions and 45 deletions

View File

@@ -9,6 +9,7 @@ from pydantic_settings import BaseSettings
from yarl import URL
from constants import API_PREFIX, CHATGPT_BASE_URI, LogLevelEnum
from core.utils import build_uri
BASE_DIR = Path(__file__).parent.parent
SHARED_DIR = BASE_DIR.resolve().joinpath("shared")
@@ -109,7 +110,7 @@ class AppSettings(SentrySettings, LoggingSettings, BaseSettings):
@cached_property
def api_prefix(self) -> str:
if self.URL_PREFIX:
return "/" + "/".join([self.URL_PREFIX.strip("/"), API_PREFIX.strip("/")])
return build_uri([self.URL_PREFIX, API_PREFIX])
return API_PREFIX
@cached_property
@@ -126,7 +127,7 @@ class AppSettings(SentrySettings, LoggingSettings, BaseSettings):
@cached_property
def bot_webhook_url(self) -> str:
return "/".join([self.api_prefix, self.token_part])
return build_uri([self.api_prefix, self.token_part])
@cached_property
def db_file(self) -> Path: