Surface transport errors from the HTTP client (fixes #184)#349
Open
TowyTowy wants to merge 1 commit into
Open
Conversation
When the PSR-18 HTTP client could not reach the API (DNS failure, connection timeout, TLS error, ...) the failure surfaced only as a generic "The response has unexpected status code (0)" message, or leaked as an implementation-specific exception. That made connection problems very hard to diagnose, as reported in mautic#184. AbstractAuth::makeRequest now catches Psr\Http\Client\ClientExceptionInterface around the sendRequest() call and rethrows a new Mautic\Exception\ConnectionException whose message includes the target URL and the underlying transport error. For cURL-based clients this carries the original cURL error message and number. The original exception is preserved as the previous exception for further inspection. Backwards compatible: ConnectionException extends AbstractApiException (and therefore \Exception), so Api::makeRequest and any caller catching \Exception keep working and now receive the richer message. Requested by @escopecz in the issue thread. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Promptless prepared a documentation update related to this change. Triggered by api-library PR #349 The PHP API library now throws a new Review: docs PR #561 |
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 #184.
When the PSR-18 HTTP client cannot reach the API (DNS failure, connection timeout, TLS error, ...), the failure previously surfaced only as a generic "unexpected status code (0)" message or leaked an implementation-specific exception, making connection problems hard to diagnose.
AbstractAuth::makeRequest()now catchesPsr\Http\Client\ClientExceptionInterfacearoundsendRequest()and rethrows a newMautic\Exception\ConnectionExceptionwhose message includes the target URL and the underlying transport error (for cURL-based clients, the original cURL error message and number). The original exception is kept asgetPrevious().Backwards compatible —
ConnectionException extends AbstractApiException(→\Exception), so existingcatch (\Exception)callers keep working and just get a better message. Adds a hermetic unit test; PHPStan, php-cs-fixer and Rector all pass.@escopecz requested a PR for this in the issue thread.