Reputation: 239
I'm using RazorPay sdk 1.6.18 in android mobile app
@Override
public void onPaymentError(int code, String response, PaymentData data) {
try {
System.out.println("Payment Error");
String errorMsg = null;
JSONObject jsonObject = new JSONObject(response);
if(jsonObject.has("error")) {
JSONObject errorJson = jsonObject.getJSONObject("error");
if(errorJson.has("description"))
errorMsg = errorJson.getString("description");
}
Toast.makeText(this, errorMsg, Toast.LENGTH_LONG).show();
} catch(Exception e) {
FirebaseCrashlytics.getInstance().recordException(e);
}
}
in onPaymentError() String response is getting empty & it's throwing exception
org.json.JSONException
End of input at character 0 of
We got this issue from crashlytics & it's affecting few users in production. Does anybody have any clue in which case response will be empty & what's a better way to handle this?
Upvotes: 0
Views: 295
Reputation: 169
Just Try,
Response strings must be checked for empty, null, or "null" status before being assigned a JSON object. then turn the response string into a JSON object. able to prevent crashes
Upvotes: 1