diff --git a/modules/swagger-codegen/src/main/resources/Java/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/Java/ApiClient.mustache index 239ce54a34a..45987bded75 100644 --- a/modules/swagger-codegen/src/main/resources/Java/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/ApiClient.mustache @@ -157,7 +157,7 @@ public class ApiClient { } } catch (IOException e) { - throw new ApiException(500, e.getMessage()); + throw new ApiException(500, e.getMessage(), null, json); } } @@ -260,9 +260,11 @@ public class ApiClient { } else { String message = "error"; + String respBody = null; if(response.hasEntity()) { try{ - message = String.valueOf(response.getEntity(String.class)); + respBody = String.valueOf(response.getEntity(String.class)); + message = respBody; } catch (RuntimeException e) { // e.printStackTrace(); @@ -270,7 +272,9 @@ public class ApiClient { } throw new ApiException( response.getClientResponseStatus().getStatusCode(), - message); + message, + response.getHeaders(), + respBody); } } diff --git a/modules/swagger-codegen/src/main/resources/Java/apiException.mustache b/modules/swagger-codegen/src/main/resources/Java/apiException.mustache index a6bcba75b7c..aac7caaf019 100644 --- a/modules/swagger-codegen/src/main/resources/Java/apiException.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/apiException.mustache @@ -1,8 +1,13 @@ package {{invokerPackage}}; +import java.util.Map; +import java.util.List; + public class ApiException extends Exception { - int code = 0; - String message = null; + private int code = 0; + private String message = null; + private Map> responseHeaders = null; + private String responseBody = null; public ApiException() {} @@ -11,19 +16,42 @@ public class ApiException extends Exception { this.message = message; } + public ApiException(int code, String message, Map> responseHeaders, String responseBody) { + this.code = code; + this.message = message; + this.responseHeaders = responseHeaders; + this.responseBody = responseBody; + } + public int getCode() { return code; } - + public void setCode(int code) { this.code = code; } - + public String getMessage() { return message; } - + public void setMessage(String message) { this.message = message; } -} \ No newline at end of file + + public Map> getResponseHeaders() { + return responseHeaders; + } + + public void setResponseHeaders(Map> responseHeaders) { + this.responseHeaders = responseHeaders; + } + + public String getResponseBody() { + return responseBody; + } + + public void setResponseBody(String responseBody) { + this.responseBody = responseBody; + } +} diff --git a/samples/client/petstore/java/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/src/main/java/io/swagger/client/ApiClient.java index ec0a150ef4e..6a4dfffefab 100644 --- a/samples/client/petstore/java/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/src/main/java/io/swagger/client/ApiClient.java @@ -157,7 +157,7 @@ public class ApiClient { } } catch (IOException e) { - throw new ApiException(500, e.getMessage()); + throw new ApiException(500, e.getMessage(), null, json); } } @@ -260,9 +260,11 @@ public class ApiClient { } else { String message = "error"; + String respBody = null; if(response.hasEntity()) { try{ - message = String.valueOf(response.getEntity(String.class)); + respBody = String.valueOf(response.getEntity(String.class)); + message = respBody; } catch (RuntimeException e) { // e.printStackTrace(); @@ -270,7 +272,9 @@ public class ApiClient { } throw new ApiException( response.getClientResponseStatus().getStatusCode(), - message); + message, + response.getHeaders(), + respBody); } } diff --git a/samples/client/petstore/java/src/main/java/io/swagger/client/ApiException.java b/samples/client/petstore/java/src/main/java/io/swagger/client/ApiException.java index 31bc8a0978a..515c21d85d4 100644 --- a/samples/client/petstore/java/src/main/java/io/swagger/client/ApiException.java +++ b/samples/client/petstore/java/src/main/java/io/swagger/client/ApiException.java @@ -1,8 +1,13 @@ package io.swagger.client; +import java.util.Map; +import java.util.List; + public class ApiException extends Exception { - int code = 0; - String message = null; + private int code = 0; + private String message = null; + private Map> responseHeaders = null; + private String responseBody = null; public ApiException() {} @@ -11,19 +16,42 @@ public class ApiException extends Exception { this.message = message; } + public ApiException(int code, String message, Map> responseHeaders, String responseBody) { + this.code = code; + this.message = message; + this.responseHeaders = responseHeaders; + this.responseBody = responseBody; + } + public int getCode() { return code; } - + public void setCode(int code) { this.code = code; } - + public String getMessage() { return message; } - + public void setMessage(String message) { this.message = message; } -} \ No newline at end of file + + public Map> getResponseHeaders() { + return responseHeaders; + } + + public void setResponseHeaders(Map> responseHeaders) { + this.responseHeaders = responseHeaders; + } + + public String getResponseBody() { + return responseBody; + } + + public void setResponseBody(String responseBody) { + this.responseBody = responseBody; + } +}