Store response headers and body in ApiException

This commit is contained in:
xhh 2015-06-02 15:33:44 +08:00
parent a8c526efd5
commit 19540ed7f0
4 changed files with 82 additions and 18 deletions

View File

@ -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);
}
}

View File

@ -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<String, List<String>> responseHeaders = null;
private String responseBody = null;
public ApiException() {}
@ -11,6 +16,13 @@ public class ApiException extends Exception {
this.message = message;
}
public ApiException(int code, String message, Map<String, List<String>> responseHeaders, String responseBody) {
this.code = code;
this.message = message;
this.responseHeaders = responseHeaders;
this.responseBody = responseBody;
}
public int getCode() {
return code;
}
@ -26,4 +38,20 @@ public class ApiException extends Exception {
public void setMessage(String message) {
this.message = message;
}
public Map<String, List<String>> getResponseHeaders() {
return responseHeaders;
}
public void setResponseHeaders(Map<String, List<String>> responseHeaders) {
this.responseHeaders = responseHeaders;
}
public String getResponseBody() {
return responseBody;
}
public void setResponseBody(String responseBody) {
this.responseBody = responseBody;
}
}

View File

@ -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);
}
}

View File

@ -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<String, List<String>> responseHeaders = null;
private String responseBody = null;
public ApiException() {}
@ -11,6 +16,13 @@ public class ApiException extends Exception {
this.message = message;
}
public ApiException(int code, String message, Map<String, List<String>> responseHeaders, String responseBody) {
this.code = code;
this.message = message;
this.responseHeaders = responseHeaders;
this.responseBody = responseBody;
}
public int getCode() {
return code;
}
@ -26,4 +38,20 @@ public class ApiException extends Exception {
public void setMessage(String message) {
this.message = message;
}
public Map<String, List<String>> getResponseHeaders() {
return responseHeaders;
}
public void setResponseHeaders(Map<String, List<String>> responseHeaders) {
this.responseHeaders = responseHeaders;
}
public String getResponseBody() {
return responseBody;
}
public void setResponseBody(String responseBody) {
this.responseBody = responseBody;
}
}