Skip to content

Conversation

@GauravGavhane18
Copy link

Refactored ApiClient to use static final constants for configuration values like API_BASE_URL, connection timeout, and read timeout.

Improved response handling to avoid NullPointerException by adding proper null checks and handling both success and error responses.

Ensured exceptions are caught and returned as readable messages instead of crashing the application.

This change addresses the previous null pointer issue in ApiClient.

Refactor ApiClient to use static final constants and improve response handling.
@GauravGavhane18 GauravGavhane18 marked this pull request as draft January 8, 2026 13:11
@GauravGavhane18 GauravGavhane18 marked this pull request as ready for review January 8, 2026 13:47
@cb-reshamsapkota
Copy link

cb-reshamsapkota commented Jan 14, 2026

While refreshing the oauth access token, if refresh token is already revoked, and if we do grant_type as refresh_token,
we get error object as:

    "error": {
        "description": "Token is already revoked"
    }
}

Here we don't have code key in error object, because of which we are getting RunTimeException instead of 4xx error.
I see this is being fixed in this PR.

private void throwException(int statusCode, JSONObject responseJson) throws RazorpayException {
        if (responseJson.has("error")) {
            JSONObject errorResponse = responseJson.getJSONObject("error");
            String code = errorResponse.getString("code");
            String description = errorResponse.getString("description");
            throw new RazorpayException(code + ":" + description);
        } else {
            this.throwServerException(statusCode, responseJson.toString());
        }
    }

But can we also include code for this error ? In that case, there would be no need for us to upgrade SDK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants