Skip to content

Unified error translation across all HTTP backends - #16

Merged
goduni merged 7 commits into
goduni:masterfrom
m-xim:errors
Sep 15, 2026
Merged

goduni merged 7 commits into
goduni:masterfrom
m-xim:errors

Conversation

@m-xim

@m-xim m-xim commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Description

Every client backend now translates its own exceptions into unihttp exceptions,
so application code never needs backend-specific except clauses.

  • New NonRetryableError for requests that cannot succeed as sent, for example an unsupported URL scheme or an invalid URL or base_url. Retrying it does not help.
  • Nothing escapes untranslated. Failures raised while sending a request or reading its body that are not a timeout, network error or non-retryable error are raised as plain UniHTTPError. The original exception is kept as __cause__.
  • Plain UniHTTPError is never a NetworkError, so RetryMiddleware(exceptions=[NetworkError, RequestTimeoutError]) does not retry it.
  • Translation is done by one helper, unihttp.clients.errors.translate_errors, driven by an ordered per-backend _ERROR_MAP, instead of per-client try/except chains.
  • urllib streaming no longer truncates silently. A body shorter than its Content-Length used to end the stream early; it now raises NetworkError.

Breaking changes

  • Backend exceptions are no longer raised directly.
    Code catching httpx.RemoteProtocolError, requests.exceptions.TooManyRedirects, aiohttp.ClientPayloadError, zapros.ReadError and similar must catch the unihttp type; the original is in __cause__.
  • Connect timeouts are timeouts.
    requests/niquests ConnectTimeout and aiohttp ServerTimeoutError (including ConnectionTimeoutError and SocketTimeoutError) now raise RequestTimeoutError instead of NetworkError.
  • Backend-level raise_for_status is not supported.
    aiohttp.ClientSession(raise_for_status=True) or a response hook calling raise_for_status() fails before on_error, handle_error and middleware see the response, and now raises plain UniHTTPError. Use ErrorMapperMiddleware.
  • niquests:
    MissingSchema, InvalidSchema, InvalidURL, InvalidHeader, InvalidJSONError, URLRequired, TooManyRedirects, ContentDecodingError, UnrewindableBodyError now raise NonRetryableError instead of NetworkError. A bare RequestException, HTTPError and StreamConsumedError now raise plain UniHTTPError instead of NetworkError.
  • urllib:
    • A URLError whose reason is not an OSError (unknown url type, no host given) raises NonRetryableError instead of NetworkError.
    • http.client.InvalidURL raises NonRetryableError; other rare http.client.HTTPExceptions (LineTooLong, UnknownProtocol, …) raise plain UniHTTPError. Truncated bodies and dropped connections are still NetworkError.
    • __cause__ is the underlying error (for example ConnectionRefusedError), not the URLError wrapper; the message no longer has the <urlopen error ...> prefix.
    • make_request closes the response after reading the body, also on success.

Type of change

  • Documentation (typos, code examples, or any documentation updates)
  • Bug fix (a non-breaking change that resolves an issue)
  • New feature (a non-breaking change that adds functionality)
  • Breaking change (a fix or feature that would disrupt existing functionality)
  • This change requires a documentation update

Checklist

  • My code adheres to the style guidelines of this project (just lint shows no errors)
  • I have conducted a self-review of my own code
  • I have made the necessary changes to the documentation
  • My changes do not generate any new warnings
  • I have added tests to validate the effectiveness of my fix or the functionality of my new feature
  • I have ensured that static analysis tests are passing by running just static-analysis
  • I have included code examples to illustrate the modifications

@codecov

codecov Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (a45033d) to head (88ca854).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@goduni
goduni merged commit 8f8550d into goduni:master Sep 15, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants