Skip to content

Commit

Permalink
Add public models for errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ob-stripe committed Feb 16, 2019
1 parent 6b10548 commit b222379
Show file tree
Hide file tree
Showing 13 changed files with 326 additions and 102 deletions.
15 changes: 3 additions & 12 deletions src/main/java/com/stripe/exception/CardException.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.stripe.exception;

import lombok.Getter;

@Getter
public class CardException extends StripeException {
private static final long serialVersionUID = 2L;

Expand All @@ -17,16 +20,4 @@ public CardException(String message, String requestId, String code, String param
this.declineCode = declineCode;
this.charge = charge;
}

public String getParam() {
return param;
}

public String getDeclineCode() {
return declineCode;
}

public String getCharge() {
return charge;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.stripe.exception;

import lombok.Getter;

@Getter
public class InvalidRequestException extends StripeException {
private static final long serialVersionUID = 2L;

Expand All @@ -10,8 +13,4 @@ public InvalidRequestException(String message, String param, String requestId, S
super(message, requestId, code, statusCode, e);
this.param = param;
}

public String getParam() {
return param;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.stripe.exception;

import lombok.Getter;

@Getter
public class SignatureVerificationException extends StripeException {
private static final long serialVersionUID = 2L;

Expand All @@ -9,8 +12,4 @@ public SignatureVerificationException(String message, String sigHeader) {
super(message, null, null, 0);
this.sigHeader = sigHeader;
}

public String getSigHeader() {
return sigHeader;
}
}
24 changes: 12 additions & 12 deletions src/main/java/com/stripe/exception/StripeException.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
package com.stripe.exception;

import com.stripe.model.StripeError;

import lombok.Getter;
import lombok.Setter;

@Getter
public abstract class StripeException extends Exception {
private static final long serialVersionUID = 2L;

/**
* The error resource returned by Stripe's API that caused the exception.
*/
@Setter
StripeError stripeError;

private String code;
private String requestId;
private Integer statusCode;
Expand All @@ -22,18 +34,6 @@ public StripeException(String message, String requestId, String code, Integer st
this.statusCode = statusCode;
}

public String getCode() {
return code;
}

public String getRequestId() {
return requestId;
}

public Integer getStatusCode() {
return statusCode;
}

/**
* Returns a description of the exception, including the HTTP status code and request ID (if
* applicable).
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/stripe/exception/oauth/OAuthException.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
package com.stripe.exception.oauth;

import com.stripe.exception.StripeException;
import com.stripe.model.oauth.OAuthError;

import lombok.Getter;
import lombok.Setter;

/**
* Base parent class for all OAuth exceptions.
*/
@Getter
public class OAuthException extends StripeException {
private static final long serialVersionUID = 2L;

/**
* The error resource returned by Stripe's OAuth API that caused the exception.
*/
@Setter
OAuthError oauthError;

public OAuthException(String code, String description, String requestId, Integer statusCode,
Throwable e) {
super(description, requestId, code, statusCode, e);
Expand Down
62 changes: 62 additions & 0 deletions src/main/java/com/stripe/model/StripeError.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.stripe.model;

import com.google.gson.annotations.SerializedName;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@EqualsAndHashCode(callSuper = false)
public class StripeError extends StripeObject {
/** For card errors, the ID of the failed charge. */
@SerializedName("charge")
String charge;

/**
* For some errors that could be handled programmatically, a short string indicating the [error
* code](/docs/error-codes) reported.
*/
@SerializedName("code")
String code;

/**
* For card errors resulting from a card issuer decline, a short string indicating the [card
* issuer's reason for the decline](/docs/declines#issuer-declines) if they provide one.
*/
@SerializedName("decline_code")
String declineCode;

/** A URL to more information about the [error code](/docs/error-codes) reported. */
@SerializedName("doc_url")
String docUrl;

/**
* A human-readable message providing more details about the error. For card errors, these
* messages can be shown to your users.
*/
@SerializedName("message")
String message;

/**
* If the error is parameter-specific, the parameter related to the error. For example, you can
* use this to display a message near the correct form field.
*/
@SerializedName("param")
String param;

// TODO: add `payment_method`

/**
* The source object for errors returned on a request involving a source.
*/
@SerializedName("source")
ExternalAccount source;

/**
* The type of error returned. One of `api_connection_error`, `api_error`, `authentication_error`,
* `card_error`, `idempotency_error`, `invalid_request_error`, or `rate_limit_error`
*/
@SerializedName("type")
String type;
}
15 changes: 15 additions & 0 deletions src/main/java/com/stripe/model/oauth/OAuthError.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.stripe.model.oauth;

import com.stripe.model.StripeObject;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@EqualsAndHashCode(callSuper = false)
public class OAuthError extends StripeObject {
String error;
String errorDescription;
}

0 comments on commit b222379

Please sign in to comment.