Adapter/Guzzle: Fix error handling for v4 API #164
Merged
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.
This commit represents a partial overhaul of error handling for requests
made against the v4 Cloudflare API, with an aim of unifying disparate
kinds of exceptions under a single
ResponseException
type, and thecovering of additional cases where errors were unhandled. Specifically:
The
Guzzle::request()
function will now catch Guzzle exceptionsnormally thrown in cases of client and server errors (4xx and 5xx)
response codes, and convert these to
ResponseException
typesbefore re-throwing. These types of errors were previously not caught
and were instead returned verbatim, expecting downstream clients to
be aware of internal details of how these functions operate.
Conversely, we no longer assume that all responses are JSON-encoded,
and no longer try to derive errors from non-4xx or 5xx responses.
All public endpoints under the v4 API are expected to be
well-behaved in that regard, and never return an error response
where none is indicated in the HTTP code.
Code has been moved around and test-cases added in support of these
changes. In most cases, these changes won't break any existing
expectations and won't require any changes to downstream code, but users
of the Cloudflare SDK should ensure that they are indeed set up for
catching
ResponseException
instances thrown during requests, andshould not expect to see Guzzle exceptions directly (though these are
still available in calls to
ResponseException::getPrevious()
).Fixes: #152