Expõe a mensagem de erro da API quando a requisição falha no multi_format_api#92
Draft
gabrielbressan-tfy wants to merge 1 commit into
Draft
Expõe a mensagem de erro da API quando a requisição falha no multi_format_api#92gabrielbressan-tfy wants to merge 1 commit into
gabrielbressan-tfy wants to merge 1 commit into
Conversation
On a failed HTTP request the handler raised only requests' status line
("400 Client Error: Bad Request for url: ..."), discarding the response body.
APIs typically return the actual reason there (e.g. {"error": "..."}), so users
had to guess why a request failed. Extract that message (JSON error/message/detail,
else truncated raw body) and append it to the raised error and the log.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Contexto
Quando uma requisição HTTP do handler
multi_format_apifalha, o erro propagado continha apenas a linha de status dorequests(ex.:400 Client Error: Bad Request for url: ...). O corpo da resposta — onde as APIs normalmente explicam o motivo real — era descartado.Isso obrigava a adivinhar a causa. Exemplo real: a API da massive.com responde
{"status":"ERROR","error":"API Key was not provided"}(e mensagens análogas para parâmetros inválidos), mas nada disso chegava ao usuário; só aparecia o400/401genérico.O que foi implementado
Um helper que extrai a mensagem de erro do corpo da resposta que falhou e a anexa tanto ao erro levantado quanto ao log:
error/message/detail;Sem corpo disponível, o comportamento é o de antes.
Arquitetura e decisões
.text.Pontos de atenção para review
| API error: API Key was not providedem vez de só a linha de status.🤖 Generated with Claude Code