@Test public void parseError_withNoErrorMessage_addsInvalidResponseMessage() { ErrorParser.StripeError badStripeError = ErrorParser.parseError(RAW_INCORRECT_FORMAT_ERROR); assertEquals(ErrorParser.MALFORMED_RESPONSE_MESSAGE, badStripeError.message); assertNull(badStripeError.type); }
@NonNull static StripeError parseError(String rawError) { StripeError stripeError = new StripeError(); try { JSONObject jsonError = new JSONObject(rawError); JSONObject errorObject = jsonError.getJSONObject(FIELD_ERROR); stripeError.charge = errorObject.optString(FIELD_CHARGE); stripeError.code = errorObject.optString(FIELD_CODE); stripeError.decline_code = errorObject.optString(FIELD_DECLINE_CODE); stripeError.message = errorObject.optString(FIELD_MESSAGE); stripeError.param = errorObject.optString(FIELD_PARAM); stripeError.type = errorObject.optString(FIELD_TYPE); } catch (JSONException jsonException) { stripeError.message = MALFORMED_RESPONSE_MESSAGE; } return stripeError; }
ErrorParser { @NonNull static StripeError parseError(String rawError) { StripeError stripeError = new StripeError(); try { JSONObject jsonError = new JSONObject(rawError); JSONObject errorObject = jsonError.getJSONObject(FIELD_ERROR); stripeError.charge = errorObject.optString(FIELD_CHARGE); stripeError.code = errorObject.optString(FIELD_CODE); stripeError.decline_code = errorObject.optString(FIELD_DECLINE_CODE); stripeError.message = errorObject.optString(FIELD_MESSAGE); stripeError.param = errorObject.optString(FIELD_PARAM); stripeError.type = errorObject.optString(FIELD_TYPE); } catch (JSONException jsonException) { stripeError.message = MALFORMED_RESPONSE_MESSAGE; } return stripeError; } }
ErrorParser { @NonNull static StripeError parseError(String rawError) { StripeError stripeError = new StripeError(); try { JSONObject jsonError = new JSONObject(rawError); JSONObject errorObject = jsonError.getJSONObject(FIELD_ERROR); stripeError.charge = errorObject.optString(FIELD_CHARGE); stripeError.code = errorObject.optString(FIELD_CODE); stripeError.decline_code = errorObject.optString(FIELD_DECLINE_CODE); stripeError.message = errorObject.optString(FIELD_MESSAGE); stripeError.param = errorObject.optString(FIELD_PARAM); stripeError.type = errorObject.optString(FIELD_TYPE); } catch (JSONException jsonException) { stripeError.message = MALFORMED_RESPONSE_MESSAGE; } return stripeError; }  }
ErrorParser { @NonNull static StripeError parseError(String rawError) { StripeError stripeError = new StripeError(); try { JSONObject jsonError = new JSONObject(rawError); JSONObject errorObject = jsonError.getJSONObject(FIELD_ERROR); stripeError.charge = errorObject.optString(FIELD_CHARGE); stripeError.code = errorObject.optString(FIELD_CODE); stripeError.decline_code = errorObject.optString(FIELD_DECLINE_CODE); stripeError.message = errorObject.optString(FIELD_MESSAGE); stripeError.param = errorObject.optString(FIELD_PARAM); stripeError.type = errorObject.optString(FIELD_TYPE); } catch (JSONException jsonException) { stripeError.message = MALFORMED_RESPONSE_MESSAGE; } return stripeError; }   }
ErrorParser { @NonNull static StripeError parseError(String rawError) { StripeError stripeError = new StripeError(); try { JSONObject jsonError = new JSONObject(rawError); JSONObject errorObject = jsonError.getJSONObject(FIELD_ERROR); stripeError.charge = errorObject.optString(FIELD_CHARGE); stripeError.code = errorObject.optString(FIELD_CODE); stripeError.decline_code = errorObject.optString(FIELD_DECLINE_CODE); stripeError.message = errorObject.optString(FIELD_MESSAGE); stripeError.param = errorObject.optString(FIELD_PARAM); stripeError.type = errorObject.optString(FIELD_TYPE); } catch (JSONException jsonException) { stripeError.message = MALFORMED_RESPONSE_MESSAGE; } return stripeError; }    }