@Test public void parseError_withInvalidRequestError_createsCorrectObject() { ErrorParser.StripeError parsedStripeError = ErrorParser.parseError(RAW_INVALID_REQUEST_ERROR); String errorMessage = "The Stripe API is only accessible over HTTPS. " + "Please see <https: assertEquals(errorMessage, parsedStripeError.message); assertEquals("invalid_request_error", parsedStripeError.type); assertEquals("", parsedStripeError.param); }
@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; }    }