more error handling
This commit is contained in:
parent
95c6ecf8b4
commit
44c4f4045f
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user