Skip to content

Commit

Permalink
move some methods around
Browse files Browse the repository at this point in the history
  • Loading branch information
xavdid-stripe committed Jan 30, 2025
1 parent 2db7b1b commit ac5753b
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions src/main/java/com/stripe/exception/StripeException.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,24 @@ protected StripeException(
}

/**
* Returns a developer-facing description of the exception, including the HTTP status code and
* request ID (if applicable).
* Returns a description of the issue suitable to show an end-user (if available).
*
* @return a string representation of the user facing exception (or `null`).
*/
public String getUserMessage() {
if (this.stripeError == null) {
return null;
}
// pulls the `user_message` field, which _may_ be present in v2 errors
return this.stripeError.getUserMessage();
}

/**
* Returns a developer-facing description of the exception, including the HTTP status code and request ID (if applicable). Not suitable for showing to end users.
*
* @return a string representation of the exception.
*/
@Override
public String getMessage() {
public String getDebugMessage() {
String additionalInfo = "";
if (code != null) {
additionalInfo += "; code: " + code;
Expand All @@ -86,19 +97,6 @@ public String getMessage() {
return super.getMessage() + additionalInfo;
}

/**
* Returns a description of the issue suitable to show an end-user (if available).
*
* @return a string representation of the user facing exception (or null).
*/
public String getUserMessage() {
// only V2 errors have (optional) user messages
if (this.getStripeError() != null && stripeErrorApiMode == ApiMode.V2) {
return this.getStripeError().getUserMessage();
}
return null;
}

public static StripeException parseV2Exception(
String type,
JsonObject body,
Expand Down

0 comments on commit ac5753b

Please sign in to comment.