diff --git a/CHANGELOG.md b/CHANGELOG.md index 0906974d..35474f51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## Version 1.4.10 - 2026-07-29 +* feat: expose structured API error data in `RazorpayException` + * `ApiClient` now parses the API error body and attaches it to the exception, so callers no longer need to parse the response themselves + * New getters on `RazorpayException`: `getCode()`, `getDescription()`, `getField()`, `getReason()`, `getSource()`, `getStep()`, `getMetadata()`, and `getErrorResponse()` for the full error JSON + * `getStatusCode()` returns the HTTP status code from the failed response + * Backwards compatible: existing constructors and `getMessage()` behavior are unchanged + ## Version 1.4.9 - 2026-06-09 * fix: use random nonce per call in AES-GCM onboarding signature diff --git a/README.md b/README.md index e0f0110c..d8c36159 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Add this dependency to your project's POM: com.razorpay razorpay-java - 1.4.9 + 1.4.10 ``` @@ -64,6 +64,26 @@ Map headers = new HashMap(); razorpayClient.addHeaders(headers); ``` +## Error Handling + +SDK calls throw `RazorpayException` on API errors. In addition to the message, you can access structured error data returned by the API: + +```java +try { + Order order = razorpayClient.orders.create(orderRequest); +} catch (RazorpayException e) { + int httpStatus = e.getStatusCode(); // HTTP status code (e.g. 400) + String code = e.getCode(); // e.g. "BAD_REQUEST_ERROR" + String description = e.getDescription(); // human-readable message + String field = e.getField(); // offending field, if any + String reason = e.getReason(); + String source = e.getSource(); + String step = e.getStep(); + JSONObject metadata = e.getMetadata(); + JSONObject raw = e.getErrorResponse(); // full error JSON +} +``` + ## Supported Resources - [Addon](documents/addon.md) diff --git a/pom.xml b/pom.xml index a7b20c13..94240c6f 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.razorpay razorpay-java - 1.4.9 + 1.4.10 jar razorpay-java