[RFC] Return Response objects from the API methods #19
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 fails CI right now because I haven't touched the tests at all, but this serves as an RFC/demo of sorts for how I want to see our social packages structured in 2.0.
In the 1.0 code, our response handlers check for an expected response code and if it doesn't exist, we throw an Exception with an error message and the response code, and on a successful response we return the Response object's decoded body. This limits the usefulness of the API data as we strip away the full response data in both success and error conditions.
This restructures the package to always return a Response object. The success scenario will simply return the Response object unaltered, the fail scenario will still check the response body and throw an Exception, but will now throw the
UnexpectedResponseException
added to the HTTP package which requires the Response object to be attached to it.I've elected to bump to the HTTP 2.0 package here in order to use our PSR-7 based Response object, which forces a PHP 5.4 bump based on the underlying dependencies.
Thoughts?