Skip to content

Commit

Permalink
Exceptions fix + Pv2 (#12)
Browse files Browse the repository at this point in the history
* Exceptions fix + Pv2

* Black + isort

* Fix test

* Update requirements.txt

* Fixing

* Update file.py

* Fix

* Fix (again)
  • Loading branch information
Wudext authored Aug 3, 2023
1 parent b596052 commit f478f3d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions file_converter/routes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ async def dispatch(self, request: Request, call_next: RequestResponseEndpoint) -
app.add_middleware(LimitUploadSize, max_upload_size=settings.MAX_SIZE)


@app.exception_handler(aiohttp.client_exceptions.ClientConnectorError)
async def not_found_error(request: Request, exc: aiohttp.client_exceptions.ClientConnectorError):
@app.exception_handler(aiohttp.ClientConnectorError)
async def not_found_error(request: Request, exc: aiohttp.ClientConnectorError):
raise HTTPException(404, f"request failed: {exc} ")


Expand Down
8 changes: 6 additions & 2 deletions file_converter/routes/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ async def process(

except UnsupportedToExt:
raise HTTPException(
status_code=415, detail=f'Files are allowed to be converted only to {", ".join(settings.CONVERT_TYPES)}'
status_code=415,
detail=f'Files are allowed to be converted only to {", ".join(settings.CONVERT_TYPES)}',
)

except ConvertError:
Expand All @@ -43,4 +44,7 @@ async def process(
raise HTTPException(status_code=415, detail=f'Only {", ".join(settings.EXTENTIONS)} files are allowed.')

root_path = settings.ROOT_PATH.removesuffix('/')
return {"status": "Success", "file_url": f'{root_path}/{settings.STATIC_FOLDER}/{result}'} # Отдает URL на файл
return {
"status": "Success",
"file_url": f'{root_path}/{str(settings.STATIC_FOLDER)}/{result}',
} # Отдает URL на файл
9 changes: 3 additions & 6 deletions file_converter/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from functools import lru_cache
from typing import List

from pydantic import BaseSettings, DirectoryPath
from pydantic import ConfigDict, DirectoryPath
from pydantic_settings import BaseSettings


class Settings(BaseSettings):
Expand All @@ -18,11 +19,7 @@ class Settings(BaseSettings):
MAX_SIZE: int = 5000000 # Максимальный размер файла в байтах
STATIC_FOLDER: DirectoryPath | None = "static"

class Config:
"""Pydantic BaseSettings config"""

case_sensitive = True
env_file = ".env"
model_config = ConfigDict(case_sensitive=True, env_file=".env", extra="ignore")


@lru_cache
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
fastapi
pydantic[dotenv]
pydantic
pydantic_settings
uvicorn
gunicorn
aiofiles
Expand Down

0 comments on commit f478f3d

Please sign in to comment.