Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions b2sdk/_internal/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,10 @@ class ServiceError(TransientErrorMixin, B2Error):
"""


class RequestTimeout(TransientErrorMixin, B2Error):
"""Used for HTTP status code 408 (request timeout)."""


class CapExceeded(B2Error):
def __str__(self):
return 'Cap exceeded.'
Expand Down Expand Up @@ -750,6 +754,8 @@ def interpret_b2_error(
return Conflict()
elif status == 416 and code == 'range_not_satisfiable':
return UnsatisfiableRange()
elif status == 408:
return RequestTimeout('%d %s %s' % (status, code, message))
elif status == 429:
return TooManyRequests(retry_after_seconds=response_headers.get('retry-after'))
elif 500 <= status < 600:
Expand Down
1 change: 1 addition & 0 deletions changelog.d/605.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Retry uploads after a B2 request-timeout response (HTTP 408).
8 changes: 7 additions & 1 deletion test/unit/test_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
interpret_b2_error,
)

from b2sdk._internal.exception import ResourceNotFound
from b2sdk._internal.exception import RequestTimeout, ResourceNotFound


class TestB2Error:
Expand Down Expand Up @@ -161,6 +161,12 @@ def test_service_error(self):
assert isinstance(error, ServiceError)
assert '500 code message' == str(error)

def test_request_timeout(self):
error = interpret_b2_error(408, 'request_timeout', 'request timeout', {})
assert isinstance(error, RequestTimeout)
assert error.should_retry_upload()
assert error.should_retry_http()

def test_unknown_error(self):
error = interpret_b2_error(499, 'code', 'message', {})
assert isinstance(error, UnknownError)
Expand Down
Loading