Skip to content

Commit 267915f

Browse files
S3 endpoint: 499 instead of 500 in case of ClientDisconnect error (#106)
1 parent b0512f5 commit 267915f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

gen3workflow/routes/s3.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from botocore.credentials import Credentials
1111
import hmac
1212
from starlette.datastructures import Headers
13+
from starlette.requests import ClientDisconnect
1314
from starlette.responses import Response
1415
from starlette.status import (
1516
HTTP_400_BAD_REQUEST,
@@ -246,7 +247,12 @@ async def s3_endpoint(path: str, request: Request):
246247
# request (SigV4 streaming HTTP PUT) into a single-payload request (Normal SigV4 HTTP PUT).
247248
# We could also implement chunked signing but it's not straightforward and likely unnecessary.
248249
# Note: Chunked uploads != multipart uploads.
249-
body = await request.body()
250+
try:
251+
body = await request.body()
252+
except ClientDisconnect: # catch this to avoid throwing 500 errors
253+
raise HTTPException(
254+
499, "Client disconnected before request body was fully received"
255+
)
250256
headers = {
251257
"host": f"{user_bucket}.s3.{region}.amazonaws.com",
252258
"x-amz-date": timestamp,

0 commit comments

Comments
 (0)