Commit Graph

14 Commits

Author SHA1 Message Date
Alex Palaistras
c58f340633 Adapter/Guzzle: Fix error handling for v4 API
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 the
covering of additional cases where errors were unhandled. Specifically:

  - The `Guzzle::request()` function will now catch Guzzle exceptions
    normally thrown in cases of client and server errors (4xx and 5xx)
    response codes, and convert these to `ResponseException` types
    before 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, and
should not expect to see Guzzle exceptions directly (though these are
still available in calls to `ResponseException::getPrevious()`).

Fixes: #152
2021-05-28 10:23:50 +10:00
Darin Randal
cca073c809 Code cleanup / Quality of Life updates
Adapter::get, post, put, patch and delete all had non-optional parameters for $headers and $query or $body. These have been made optional. I also re-ordered the parameters as $headers was never used while $query/$body were heavily used. I also condensed and removed some duplicate calls so that every call to Adapter::get/post sends that call to Adapter::request. It could use a magic method to do this but it might make it more difficult to test.
2018-04-12 23:11:04 -04:00
Kleis Auke Wolthuizen
0920fc48b2 Remove unnecessary double quotes 2017-11-21 17:25:41 +01:00
Junade Ali
ca9e5bbc28 Enabled PHPMD for src and tests 2017-10-13 15:18:08 +01:00
Linus Metzler
70ee68f755 fix the test 2017-10-05 14:44:09 +02:00
Anthony Sterling
fbb5aac074 Moved JSON API Responses to test fixtures
This PR moves the JSON API responses used in the tests to fixture files
within the tests folder. This allows reuse and the ability to lint/validate
these fixtures if required - although not covered in this PR.

I've added TestCase::getPsr7StreamForFixture and TestCase::getPsr7JsonResponseForFixture
to reduce code duplication and enable some assertions around the expected fixures/responses.

Thanks,
2017-09-24 15:24:33 +01:00
Anthony Sterling
2faff272df Applied PSR2 formatting to existing files 2017-09-23 18:50:51 +01:00
Junade
b91dd5e684 Merge pull request #5 from typhonius/add-query-to-get
Adds the query parameter to the guzzle call for GET requests.
2017-09-21 23:16:50 +01:00
Adam Malone
7d838d7f5f Adds the query parameter to the guzzle call for GET requests. 2017-09-21 11:45:21 +10:00
Junade Ali
121209e4ca COM-45 :: Adjust Guzzle Tests 2017-09-20 13:25:00 +01:00
Hans
696a36d682 Change post unit test to json. 2017-08-30 17:02:09 +08:00
Junade Ali
bf8716e0b8 Finished user endpoints, started zone ones. 2017-06-06 17:05:21 +01:00
Junade Ali
5fcb00153b Finished Guzzle implementation, started work on Endpoints. 2017-02-01 18:07:33 +00:00
Junade Ali
a49c655e77 Initial commit, WIP. 2017-01-13 23:52:27 +00:00