Repository navigation
Unified error translation across all HTTP backends - #16
Merged
Merged
Conversation
…coverage for invalid base URLs
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #16 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 33 34 +1
Lines 1328 1292 -36
=========================================
- Hits 1328 1292 -36 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Every client backend now translates its own exceptions into unihttp exceptions,
so application code never needs backend-specific
exceptclauses.NonRetryableErrorfor requests that cannot succeed as sent, for example an unsupported URL scheme or an invalid URL orbase_url. Retrying it does not help.UniHTTPError. The original exception is kept as__cause__.UniHTTPErroris never aNetworkError, soRetryMiddleware(exceptions=[NetworkError, RequestTimeoutError])does not retry it.unihttp.clients.errors.translate_errors, driven by an ordered per-backend_ERROR_MAP, instead of per-clienttry/exceptchains.Content-Lengthused to end the stream early; it now raisesNetworkError.Breaking changes
Code catching
httpx.RemoteProtocolError,requests.exceptions.TooManyRedirects,aiohttp.ClientPayloadError,zapros.ReadErrorand similar must catch the unihttp type; the original is in__cause__.requests/niquests
ConnectTimeoutand aiohttpServerTimeoutError(includingConnectionTimeoutErrorandSocketTimeoutError) now raiseRequestTimeoutErrorinstead ofNetworkError.raise_for_statusis not supported.aiohttp.ClientSession(raise_for_status=True)or a response hook callingraise_for_status()fails beforeon_error,handle_errorand middleware see the response, and now raises plainUniHTTPError. UseErrorMapperMiddleware.MissingSchema,InvalidSchema,InvalidURL,InvalidHeader,InvalidJSONError,URLRequired,TooManyRedirects,ContentDecodingError,UnrewindableBodyErrornow raiseNonRetryableErrorinstead ofNetworkError. A bareRequestException,HTTPErrorandStreamConsumedErrornow raise plainUniHTTPErrorinstead ofNetworkError.URLErrorwhose reason is not anOSError(unknown url type,no host given) raisesNonRetryableErrorinstead ofNetworkError.http.client.InvalidURLraisesNonRetryableError; other rarehttp.client.HTTPExceptions (LineTooLong,UnknownProtocol, …) raise plainUniHTTPError. Truncated bodies and dropped connections are stillNetworkError.__cause__is the underlying error (for exampleConnectionRefusedError), not theURLErrorwrapper; the message no longer has the<urlopen error ...>prefix.make_requestcloses the response after reading the body, also on success.Type of change
Checklist
just lintshows no errors)just static-analysis