@Override public String toString() { return getErrorType().name() + ": " + getErrorCode(); } }
public static ErrorWithResponse fromJson(String json) throws JSONException { ErrorWithResponse errorWithResponse = new ErrorWithResponse(); errorWithResponse.mOriginalResponse = json; errorWithResponse.parseJson(json); return errorWithResponse; }
@Override public BraintreeApiErrorResponse createFromParcel(Parcel source) { return new BraintreeApiErrorResponse(source); }
@Test public void fromJson_parsesErrorsCorrectly() throws JSONException { String response = stringFromFixture("errors/credit_card_error_response.json"); ErrorWithResponse errorWithResponse = ErrorWithResponse.fromJson(response); assertEquals("Credit card is invalid", errorWithResponse.getMessage()); assertNull(errorWithResponse.errorFor("creditCard").errorFor("postalCode")); assertEquals("Credit card must include number, payment_method_nonce, or venmo_sdk_payment_method_code", errorWithResponse.errorFor("creditCard").errorFor("base").getMessage()); assertEquals("Credit card number is required", errorWithResponse.errorFor("creditCard").errorFor("number").getMessage()); assertEquals("Expiration year is invalid", errorWithResponse.errorFor("creditCard").errorFor("expirationYear").getMessage()); }
@Override protected String parseResponse(HttpURLConnection connection) throws Exception { try { return super.parseResponse(connection); } catch (AuthorizationException | UnprocessableEntityException e) { if (e instanceof AuthorizationException) { String errorMessage = new ErrorWithResponse(403, e.getMessage()).getMessage(); throw new AuthorizationException(errorMessage); } else { throw new ErrorWithResponse(422, e.getMessage()); } } } }
@Override public void onError(Exception error) { assertEquals("Postal code verification failed", ((ErrorWithResponse) error).errorFor("creditCard").errorFor("billingAddress") .getFieldErrors().get(0).getMessage()); countDownLatch.countDown(); } });
@Override public void onError(Exception error) { assertEquals("CVV verification failed", ((ErrorWithResponse) error).errorFor("creditCard").getFieldErrors().get(0).getMessage()); countDownLatch.countDown(); } });
@Override protected String parseResponse(HttpURLConnection connection) throws Exception { try { return super.parseResponse(connection); } catch (UnprocessableEntityException e) { throw new BraintreeApiErrorResponse(e.getMessage()); } } }
@Override public GooglePaymentException createFromParcel(Parcel in) { return new GooglePaymentException(in); }
public ErrorWithResponse createFromParcel(Parcel source) { return new ErrorWithResponse(source); }
@Override public void writeToParcel(Parcel dest, int flags) { dest.writeString(getMessage()); dest.writeParcelable(mStatus, 0); }
private void parseJson(String jsonString) throws JSONException { JSONObject json = new JSONObject(jsonString); mMessage = json.getJSONObject(ERROR_KEY).getString(MESSAGE_KEY); mFieldErrors = BraintreeError.fromJsonArray(json.optJSONArray(FIELD_ERRORS_KEY)); }
@Override public BraintreeApiError createFromParcel(Parcel source) { return new BraintreeApiError(source); }
@Override public String getMessage() { return toString(); }
public BraintreeError createFromParcel(Parcel source) { return new BraintreeError(source); }
public ErrorWithResponse(int statusCode, String jsonString) { mStatusCode = statusCode; mOriginalResponse = jsonString; try { parseJson(jsonString); } catch (JSONException e) { mMessage = "Parsing error response failed"; mFieldErrors = new ArrayList<>(); } }
@Override public void onConnectionSuspended(int i) { postCallback(new GoogleApiClientException(ErrorType.ConnectionSuspended, i)); } });
@Override public void failure(Exception exception) { fragment.postCallback(new PaymentMethodDeleteException(paymentMethodNonce, exception)); fragment.sendAnalyticsEvent("delete-payment-methods.failed"); } });
@Override public void onError(Exception error) { assertEquals("Country code (alpha3) is not an accepted country", ((ErrorWithResponse) error).errorFor("creditCard").errorFor("billingAddress") .getFieldErrors().get(0).getMessage()); countDownLatch.countDown(); } });
public static BraintreeApiError fromJson(JSONObject json) { BraintreeApiError error = new BraintreeApiError(); error.mCode = Json.optString(json, "code", null); error.mMessage = Json.optString(json, "developer_message", null); error.mIn = Json.optString(json, "in", null); error.mAt = Json.optString(json, "at", null); return error; }