Repository navigation
feat(errors): add RazorpayError as common base exception class - #349
Open
Sreejith088 wants to merge 1 commit into
Open
Sreejith088 wants to merge 1 commit into
Sreejith088 wants to merge 1 commit into
Conversation
Closes razorpay#52 All SDK exceptions (BadRequestError, GatewayError, ServerError, SignatureVerificationError) previously inherited directly from Python's built-in Exception, making it impossible for callers to catch all Razorpay-specific errors with a single except clause. Introduces RazorpayError(Exception) as a shared base class and updates all four exception classes to inherit from it. Also exports RazorpayError from the top-level package so users can import it alongside Client. Adds four tests: three asserting the inheritance relationship and one confirming that a live BadRequestError is catchable as RazorpayError.
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.
Summary
Closes #52
All SDK exceptions (
BadRequestError,GatewayError,ServerError,SignatureVerificationError) previously inherited directly from Python's built-inException. This meant callers had to catch each error type separately, which is both verbose and fragile — any new exception type added to the SDK would silently escape a catch-all handler.This PR introduces
RazorpayError(Exception)as a shared base class. All four existing exceptions now inherit from it, so users can write:while still being able to catch specific subtypes when needed.
RazorpayErroris also exported from the top-level package so it is available asrazorpay.RazorpayErrorwithout an extra import.Changes
razorpay/errors.py: addedRazorpayErrorbase class; updated all four exceptions to inherit from itrazorpay/__init__.py: exported all five exception classestests/test_client_error.py: added 4 tests — 3 asserting the inheritance relationships and 1 confirming a liveBadRequestErroris catchable asRazorpayErrorTest plan
test_bad_request_error_is_razorpay_errortest_gateway_error_is_razorpay_errortest_server_error_is_razorpay_errortest_catch_as_razorpay_error