Capturing error in Barte "refund_transaction"#35
Merged
avelino merged 4 commits intobuserbrasil:mainfrom Nov 26, 2025
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds explicit error handling for refund operations and introduces tests to validate the new behavior when the API returns an error response.
- Add BarteError raising on refund endpoints when the API returns an errors payload
- Ensure partial_refund_charge checks for dict response before error inspection (success is a list)
- Add tests and a fixture to validate error handling for refund and partial refund
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| barte/client.py | Adds error handling for refund_charge and partial_refund_charge by detecting "errors" in the API response and raising BarteError. |
| tests/test_client.py | Adds a refund error fixture and two tests asserting BarteError is raised for refund and partial refund error responses. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
avelino
approved these changes
Nov 26, 2025
Member
avelino
left a comment
There was a problem hiding this comment.
LGTM, PR resolve o problema proposto
porem podemos melhorar com as sugestões que trouxe aqui
BeatrizMartinsA
approved these changes
Nov 26, 2025
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.
Modificações no client.py
refund_charge(linhas 170-182): Adicionada verificação de erro que lançaBarteErrorpartial_refund_charge(linhas 184-199): Adicionada verificação de erro comisinstance(json_response, dict)antes de verificar "errors" (necessário porque o sucesso retorna uma lista)Novos testes no test_client.py
mock_refund_error_response(linhas 106-121): Resposta de erro para refundstest_refund_charge_with_error(linhas 726-739): Testa que refund_charge lançaBarteErrortest_partial_refund_charge_with_error(linhas 741-756): Testa quepartial_refund_chargelançaBarteError