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