Repository navigation
Conversation
| "message": str(flat_message), | ||
| } | ||
| ) | ||
| except (JSONDecodeError, AttributeError): |
There was a problem hiding this comment.
🟡 Mid risk — Un body con bytes no UTF-8 se salta el fallback a ApiError
Cuando una llamada normal del SDK recibe un 502 con una página HTML en Windows-1252 que incluye texto acentuado, response.json() en httpx 0.28 (permitido por el SDK) pasa los bytes directo al decoder JSON, que lanza UnicodeDecodeError antes de parsear. Esa excepción no se captura, así que la llamada falla igual que en master y una integración que captura FintocError no puede manejar el 502 por esa vía.
Ver sugerencia
Fix: Captura también UnicodeDecodeError para que el fallback use response.text y devuelva un ApiError con el status HTTP.
Suggested change
| except (JSONDecodeError, AttributeError): | |
| except (JSONDecodeError, UnicodeDecodeError, AttributeError): |
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.
Summary
Hardens HTTP status error handling in
fintoc_error_fromandFintocErroragainst non-JSON (HTML 502/503/504), empty, or malformed error responses from upstream gateways, and adds comprehensive unit test coverage.Details
fintoc/utils.py:JSONDecodeErrorandAttributeErrorwhen decoding error payloads from upstream proxies or maintenance pages (e.g., Cloudflare 502/503 HTML).ApiErrorwith the status code and available response text instead of raising an uncaughtJSONDecodeErrororKeyError.{"detail": ...}or{"message": ...}) and nestederrorobjects without atypefield.fintoc/errors.py:FintocError.__init__againstTypeErrorwhentypeis missing ormessageisNone.tests/test_errors.py:FintocErrorand its subclasses under various payloads.tests/test_utils.py:TestFintocErrorFromtest suite covering standard errors, HTML 502 Bad Gateway, empty 500 responses, flat error dicts, and untyped error objects.Release notes
error: Safely handle non-JSON and malformed HTTP error responses by raising a cleanApiError.