Expose full API error fields: source, step, reason, metadata#417
Open
rzp-slash[bot] wants to merge 2 commits into
Open
Expose full API error fields: source, step, reason, metadata#417rzp-slash[bot] wants to merge 2 commits into
rzp-slash[bot] wants to merge 2 commits into
Conversation
All error types now capture and expose the full set of fields returned by the Razorpay API error object (source, step, reason, metadata, field) via getters on the base Error class. Previously only code, description, and field (on BadRequestError) were accessible to callers. Co-authored-by: ankitdas13 <ankit.das@razorpay.com>
… scoping, metadata type safety - Fix: guard $description access with ?? '' — verifyErrorFormat only checked 'code', so a missing 'description' key produced a null exception message - Fix: call parent::__construct($message) so Exception chaining (getPrevious) works correctly - Fix: move $field back to BadRequestError only — field is a validation-domain concept and does not belong on GatewayError / ServerError - Fix: replace 8 positional params with array $context on base Error, removing fragile positional coupling for future API schema additions - Fix: getMetadata() guards against non-array values with is_array() check - Fix: use ?? operator and extract $err = $body['error'] to eliminate repeated key lookups and isset/ternary verbosity Co-authored-by: ankitdas13 <ankit.das@razorpay.com>
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.
Problem
The Razorpay API error response includes
source,step,reason, andmetadatafields alongsidecode,description, andfield. The PHP SDK was silently discarding the first four, making them inaccessible to callers.Changes
src/Errors/Error.php— Added$field,$source,$step,$reason,$metadataproperties to the base class with a unified constructor and getters (getField(),getSource(),getStep(),getReason(),getMetadata()). All error types (BadRequestError,GatewayError,ServerError) now inherit these.src/Errors/BadRequestError.php— Simplified;$fieldandgetField()now live in the baseErrorclass (backwards-compatible —getField()still works onBadRequestErrorinstances).src/Request.php—processError()now extracts all five optional fields and passes them through to the exception constructor.Backwards compatibility
getField()onBadRequestErrorcontinues to work — method moved to base class, same behaviour.GatewayErrorandServerErrorconstructors unchanged in call sites; new params default tonull.throwServerError()still calls the 3-arg form — no change needed.Usage after this fix
🤖 Generated with Claude Code