Fix TelegramBotHandler swallowing errors on non-JSON responses (#2026)#2030
Open
Pablo1Gustavo wants to merge 1 commit intoSeldaek:mainfrom
Open
Fix TelegramBotHandler swallowing errors on non-JSON responses (#2026)#2030Pablo1Gustavo wants to merge 1 commit intoSeldaek:mainfrom
Pablo1Gustavo wants to merge 1 commit intoSeldaek:mainfrom
Conversation
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.
Fixes #2026
What it solves
TelegramBotHandler::sendCurl()was silently swallowing errors whenever the Telegram API or an upstream proxy returned a non-JSON body (Cloudflare 502 pages, Nginx error pages, truncated responses, etc.).json_decode()returnednull, the guard$result['ok'] === falseevaluated tofalse(sincenull === falseisfalse), and no exception was raised — log records were lost during the exact infrastructure outages where alerting matters most.How it solves
json_decode(), reject anything that isn't a JSON object via\is_array($result), throwing aRuntimeExceptionwith a clear"Unexpected non-JSON response"message.$result['ok'] === falsewith($result['ok'] ?? null) !== true. This also catches valid JSON responses that simply lack theokkey (e.g. proxy-injected error envelopes), which the old check would silently accept."Unknown error"whendescriptionis absent, preventing the previous undefined-key warning.validateApiResponse()so each failure mode can be tested without a live HTTP call.Tests
Added a data-provider-driven test covering all six failure paths (curl failure, HTML body, empty body,
ok:falsewith/without description, missingokkey) plus a happy-path assertion. The existing tests continue to pass.