• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

stripe / stripe-java / #16443

25 Sep 2024 11:35PM UTC coverage: 16.271% (-0.06%) from 16.327%
#16443

Pull #1873

github

web-flow
Merge d9583602e into fd2e2e37a
Pull Request #1873: Next major infra

370 of 684 new or added lines in 52 files covered. (54.09%)

3 existing lines in 3 files now uncovered.

17916 of 110107 relevant lines covered (16.27%)

0.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.65
/src/main/java/com/stripe/exception/StripeException.java
1
package com.stripe.exception;
2

3
import com.google.gson.JsonObject;
4
import com.stripe.model.StripeError;
5
import com.stripe.net.StripeResponseGetter;
6
import lombok.Getter;
7

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

12
  /** The error resource returned by Stripe's API that caused the exception. */
13
  // transient so the exception can be serialized, as StripeObject does not
14
  // implement Serializable
15
  transient StripeError stripeError;
16

17
  public void setStripeError(StripeError err) {
18
    stripeError = err;
1✔
19
  }
1✔
20

21
  /**
22
   * Returns the error code of the response that triggered this exception. For {@link ApiException}
23
   * the error code will be equal to {@link StripeError#getCode()}.
24
   *
25
   * @return the string representation of the error code.
26
   */
27
  private String code;
28

29
  /**
30
   * Returns the request ID of the request that triggered this exception.
31
   *
32
   * @return the request ID.
33
   */
34
  private String requestId;
35

36
  /**
37
   * Returns the status code of the response that triggered this exception.
38
   *
39
   * @return the status code.
40
   */
41
  private Integer statusCode;
42

43
  protected StripeException(String message, String requestId, String code, Integer statusCode) {
44
    this(message, requestId, code, statusCode, null);
1✔
45
  }
1✔
46

47
  /** Constructs a new Stripe exception with the specified details. */
48
  protected StripeException(
49
      String message, String requestId, String code, Integer statusCode, Throwable e) {
50
    super(message, e);
1✔
51
    this.code = code;
1✔
52
    this.requestId = requestId;
1✔
53
    this.statusCode = statusCode;
1✔
54
  }
1✔
55

56
  /**
57
   * Returns a description of the exception, including the HTTP status code and request ID (if
58
   * applicable).
59
   *
60
   * @return a string representation of the exception.
61
   */
62
  @Override
63
  public String getMessage() {
64
    String additionalInfo = "";
1✔
65
    if (code != null) {
1✔
66
      additionalInfo += "; code: " + code;
1✔
67
    }
68
    if (requestId != null) {
1✔
69
      additionalInfo += "; request-id: " + requestId;
1✔
70
    }
71
    if (this.getUserMessage() != null) {
1✔
NEW
72
      additionalInfo += "; user-message: " + this.getUserMessage();
×
73
    }
74
    return super.getMessage() + additionalInfo;
1✔
75
  }
76

77
  /**
78
   * Returns a description of the user facing exception
79
   *
80
   * @return a string representation of the user facing exception.
81
   */
82
  public String getUserMessage() {
83
    if (this.getStripeError() != null) {
1✔
84
      return this.getStripeError().getUserMessage();
1✔
85
    }
86
    return null;
1✔
87
  }
88

89
  public static StripeException parseV2Exception(
90
      String type,
91
      JsonObject body,
92
      int statusCode,
93
      String requestId,
94
      StripeResponseGetter responseGetter) {
95
    switch (type) {
1✔
96
        // The beginning of the section generated from our OpenAPI spec
97
      case "temporary_session_expired":
98
        return com.stripe.exception.TemporarySessionExpiredException.parse(
1✔
99
            body, statusCode, requestId, responseGetter);
100
        // The end of the section generated from our OpenAPI spec
101
    }
102
    return null;
1✔
103
  }
104
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc