Title: Add transient-error classification to APIFailure by mtorp · Pull Request #93 · SocketDev/socket-sdk-python · GitHub
Open Graph Title: Add transient-error classification to APIFailure by mtorp · Pull Request #93 · SocketDev/socket-sdk-python
X Title: Add transient-error classification to APIFailure by mtorp · Pull Request #93 · SocketDev/socket-sdk-python
Description: Problem
Consumers that want to retry transient API failures have no reliable way to classify an exception. The catch-all APIFailure only embeds the HTTP status in its message text (original_status_code:), so callers must parse message strings and special-case the exception hierarchy — which breaks silently if a status code gains a dedicated subclass later. SocketDev/socket-python-cli#232 (full-scan upload retry) ran into exactly this, see review discussion.
Change
API.do_request now records the HTTP status code on every exception it raises, via a new keyword-only status_code attribute on APIFailure (default None, so all existing construction/raise sites remain valid).
APIFailure.is_transient_error() returns whether retrying the same request may succeed:
True for HTTP 408/502/503/504 (gateway/availability failures) and for APITimeout / APIConnectionError (no HTTP status — the request never completed).
False for deterministic errors: 400/401/403/404/429, and bare APIFailure() wrappers around unexpected errors.
Classification is based on the recorded status code, not exception class identity or message text. If a transient status (e.g. 503) ever gains a dedicated subclass, is_transient_error() keeps working unchanged.
Error message formats are unchanged, so existing message-parsing consumers are unaffected.
Testing
New tests/unit/test_exceptions.py (21 tests): classification truth table for direct construction, status codes attached by do_request per HTTP status (401/403/404/429/502 dedicated classes; 408/503/504 and 400/500 catch-all), timeout/connection-error mapping, and the wrapped-unexpected-error case. Full unit suite: 122 passed, 1 skipped.
Version
3.2.1 → 3.3.0 (new public API).
Open Graph Description: Problem Consumers that want to retry transient API failures have no reliable way to classify an exception. The catch-all APIFailure only embeds the HTTP status in its message text (original_status_...
X Description: Problem Consumers that want to retry transient API failures have no reliable way to classify an exception. The catch-all APIFailure only embeds the HTTP status in its message text (original_status_...
Opengraph URL: https://github.com/SocketDev/socket-sdk-python/pull/93
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:58a2c5ee-aaa5-7af3-ee99-0fecd8f4fa22 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | C71E:1FFDFF:28BFBB1:38B1393:6A4F5CC3 |
| html-safe-nonce | 9012a72512f2f92aa1f89411e22b7e71817748f09d856b58a2751cfb859f0479 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNzFFOjFGRkRGRjoyOEJGQkIxOjM4QjEzOTM6NkE0RjVDQzMiLCJ2aXNpdG9yX2lkIjoiODA4NTAxNTUxMTE2MTU5MzAyNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | c5d0e308f1baee23324ddcae41b507f6a6aaf3d3bc185276acbda70c2beed410 |
| hovercard-subject-tag | pull_request:3838985014 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/SocketDev/socket-sdk-python/pull/93/files |
| twitter:image | https://avatars.githubusercontent.com/u/5579277?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/5579277?s=400&v=4 |
| og:image:alt | Problem Consumers that want to retry transient API failures have no reliable way to classify an exception. The catch-all APIFailure only embeds the HTTP status in its message text (original_status_... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | b92d11c0aa4a77d54ef4af1078b6a15fb5a70a215b30c4ecf28889d5a8e656d9 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/SocketDev/socket-sdk-python git https://github.com/SocketDev/socket-sdk-python.git |
| octolytics-dimension-user_id | 69326764 |
| octolytics-dimension-user_login | SocketDev |
| octolytics-dimension-repository_id | 715809144 |
| octolytics-dimension-repository_nwo | SocketDev/socket-sdk-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 715809144 |
| octolytics-dimension-repository_network_root_nwo | SocketDev/socket-sdk-python |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 4b249b445842943ed31549e027f57a8ade9881ed |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width