Repository navigation
Enhances API Response Handling - #65
Merged
Merged
Conversation
Cloudflare's API often returns a 2xx status with `"success": false` and lists of `errors` or `messages` in the body. This change introduces `errors()`, `messages()`, and `hasErrors()` methods to easily inspect these envelope details. The `successful()` method now correctly identifies all 2xx HTTP statuses, aligning with various API response patterns (e.g., 201, 202, 204). Additionally, the `json()` method now supports dot notation for accessing nested values more conveniently.
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.
Updates API response parsing and error detection mechanisms:
2xxHTTP status codes, accurately reflecting Cloudflare's varied successful responses (e.g.,201,204).errors(),messages(),hasErrors()) to identify and process Cloudflare's envelope errors, which appear in the response body even when the HTTP status is2xx(e.g.,success: false).json()method to support dot notation for easier access to deeply nested data within the response payload.Changes
successful()method now evaluates totruefor any status code between200and299.errors(),messages(), andhasErrors()methods to theResponseInterfaceandResponseclass for direct access to Cloudflare's operational error and message lists.json()to simplify fetching nested data (e.g.,$response->json('result.meta.step')).gethelper method has been made private, removing it from the public contract.Benefits
Testing
2xxstatus codes to ensure thesuccessful()method behaves as expected.204 No Contentstatus.json()for nested data.errors(),messages(), andhasErrors()under various scenarios, including2xxstatuses with envelope errors and when the envelope is absent.3xxredirect statuses now consistently throwRequestException.Documentation
usage.mddocumentation to reflect the new definition of a successful response, the capabilities of dot notation injson(), and the usage of the new envelope error methods.Checklist