github.com/phrase/openapi@v0.0.0-20240514140800-49e8a106740e/openapi-generator/templates/java/libraries/jersey2-experimental/apiException.mustache (about)

     1  {{>licenseInfo}}
     2  
     3  package {{invokerPackage}};
     4  
     5  import java.util.Map;
     6  import java.util.List;
     7  {{#caseInsensitiveResponseHeaders}}
     8  import java.util.Map.Entry;		
     9  import java.util.TreeMap;
    10  {{/caseInsensitiveResponseHeaders}}
    11  
    12  /**
    13   * API Exception
    14   */
    15  {{>generatedAnnotation}}
    16  public class ApiException extends{{#useRuntimeException}} RuntimeException {{/useRuntimeException}}{{^useRuntimeException}} Exception {{/useRuntimeException}}{
    17      private int code = 0;
    18      private Map<String, List<String>> responseHeaders = null;
    19      private String responseBody = null;
    20  
    21      public ApiException() {}
    22  
    23      public ApiException(Throwable throwable) {
    24          super(throwable);
    25      }
    26  
    27      public ApiException(String message) {
    28          super(message);
    29      }
    30  
    31      public ApiException(String message, Throwable throwable, int code, Map<String, List<String>> responseHeaders, String responseBody) {
    32          super(message, throwable);
    33          this.code = code;
    34          {{#caseInsensitiveResponseHeaders}}
    35          Map<String, List<String>> headers = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER);
    36          for(Entry<String, List<String>> entry : responseHeaders.entrySet()){
    37          	headers.put(entry.getKey().toLowerCase(), entry.getValue());
    38          }
    39          {{/caseInsensitiveResponseHeaders}}
    40          this.responseHeaders = {{#caseInsensitiveResponseHeaders}}headers{{/caseInsensitiveResponseHeaders}}{{^caseInsensitiveResponseHeaders}}responseHeaders{{/caseInsensitiveResponseHeaders}};
    41          this.responseBody = responseBody;
    42      }
    43  
    44      public ApiException(String message, int code, Map<String, List<String>> responseHeaders, String responseBody) {
    45          this(message, (Throwable) null, code, responseHeaders, responseBody);
    46      }
    47  
    48      public ApiException(String message, Throwable throwable, int code, Map<String, List<String>> responseHeaders) {
    49          this(message, throwable, code, responseHeaders, null);
    50      }
    51  
    52      public ApiException(int code, Map<String, List<String>> responseHeaders, String responseBody) {
    53          this((String) null, (Throwable) null, code, responseHeaders, responseBody);
    54      }
    55  
    56      public ApiException(int code, String message) {
    57          super(message);
    58          this.code = code;
    59      }
    60  
    61      public ApiException(int code, String message, Map<String, List<String>> responseHeaders, String responseBody) {
    62          this(code, message);
    63          {{#caseInsensitiveResponseHeaders}}
    64          Map<String, List<String>> headers = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER);
    65          for(Entry<String, List<String>> entry : responseHeaders.entrySet()){
    66          	headers.put(entry.getKey().toLowerCase(), entry.getValue());
    67          }
    68          {{/caseInsensitiveResponseHeaders}}
    69          this.responseHeaders = {{#caseInsensitiveResponseHeaders}}headers{{/caseInsensitiveResponseHeaders}}{{^caseInsensitiveResponseHeaders}}responseHeaders{{/caseInsensitiveResponseHeaders}};
    70          this.responseBody = responseBody;
    71      }
    72  
    73      /**
    74       * Get the HTTP status code.
    75       *
    76       * @return HTTP status code
    77       */
    78      public int getCode() {
    79          return code;
    80      }
    81  
    82      /**
    83       * Get the HTTP response headers.
    84       *
    85       * @return A map of list of string
    86       */
    87      public Map<String, List<String>> getResponseHeaders() {
    88          return responseHeaders;
    89      }
    90  
    91      /**
    92       * Get the HTTP response body.
    93       *
    94       * @return Response body in the form of string
    95       */
    96      public String getResponseBody() {
    97          return responseBody;
    98      }
    99  }