Error Handling Correction in barte-python-sdk#36
Merged
mdcg-buser merged 5 commits intobuserbrasil:mainfrom Dec 2, 2025
Merged
Error Handling Correction in barte-python-sdk#36mdcg-buser merged 5 commits intobuserbrasil:mainfrom
mdcg-buser merged 5 commits intobuserbrasil:mainfrom
Conversation
walison17
reviewed
Dec 1, 2025
walison17
approved these changes
Dec 2, 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.
Problema Identificado
O método
_requestemclient.pychamaresponse.raise_for_status()antes de processar o corpo da resposta. Quando a API retorna um erro HTTP (4xx/5xx), oraise_for_status()lança uma exceçãorequests.exceptions.HTTPErrorgenérica, impedindo que:response.json()seja chamadoErrorResponseBarteError"rico em contexto" seja lançadoResultado: Usuários recebem
HTTPErrorgenérico ao invés deBarteErrorcom informações úteis (code, action, charge_uuid).Resumo das mudanças
Arquivo modificado:
client.py1. Método
_requestraise_for_status()prematuro que suprimia os erros da APIraise_for_status()apenas como fallback para erros sem corpo estruturado2. Remoção de código duplicado
create_order,refund_chargeepartial_refund_chargeAgora quando a API retorna um erro, você receberá um
BarteErrorcom todas as informações:code: código do erro (ex: "BAR-7005")
message: descrição do erroaction: ação recomendadacharge_uuid: UUID da cobrança relacionada (quando aplicável)response: objeto de resposta completo