more error handling

This commit is contained in:
Kristian Krsnik 2024-04-12 15:17:40 +02:00
parent 95c6ecf8b4
commit 44c4f4045f
Signed by: Kristian
GPG Key ID: FD1330AC9F909E85
2 changed files with 8 additions and 1 deletions

View File

@ -52,7 +52,13 @@ def test_data(api_key: str, request: Request, size: str) -> StreamingResponse:
detail='Invalid API Key.'
)
size = convert_to_bytes(size)
try:
size = convert_to_bytes(size)
except ValueError:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail='Invalid format format for size.'
)
if size < 0:
raise MinSizePerRequestError

View File

@ -17,6 +17,7 @@ def convert_to_bytes(size: int | str) -> int:
return int(float(size.removesuffix(unit)) * units[unit])
break
raise ValueError
async def generate_data(size: int, buffer_size: int = 4 * 1024) -> bytes:
size_left = size