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) { 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 { else {
String message = "error"; String message = "error";
String respBody = null;
if(response.hasEntity()) { if(response.hasEntity()) {
try{ try{
message = String.valueOf(response.getEntity(String.class)); respBody = String.valueOf(response.getEntity(String.class));
message = respBody;
} }
catch (RuntimeException e) { catch (RuntimeException e) {
// e.printStackTrace(); // e.printStackTrace();
@ -270,7 +272,9 @@ public class ApiClient {
} }
throw new ApiException( throw new ApiException(
response.getClientResponseStatus().getStatusCode(), response.getClientResponseStatus().getStatusCode(),
message); message,
response.getHeaders(),
respBody);
} }
} }

View File

@ -1,8 +1,13 @@
package {{invokerPackage}}; package {{invokerPackage}};
import java.util.Map;
import java.util.List;
public class ApiException extends Exception { public class ApiException extends Exception {
int code = 0; private int code = 0;
String message = null; private String message = null;
private Map<String, List<String>> responseHeaders = null;
private String responseBody = null;
public ApiException() {} public ApiException() {}
@ -11,19 +16,42 @@ public class ApiException extends Exception {
this.message = message; 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() { public int getCode() {
return code; return code;
} }
public void setCode(int code) { public void setCode(int code) {
this.code = code; this.code = code;
} }
public String getMessage() { public String getMessage() {
return message; return message;
} }
public void setMessage(String message) { public void setMessage(String message) {
this.message = 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) { 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 { else {
String message = "error"; String message = "error";
String respBody = null;
if(response.hasEntity()) { if(response.hasEntity()) {
try{ try{
message = String.valueOf(response.getEntity(String.class)); respBody = String.valueOf(response.getEntity(String.class));
message = respBody;
} }
catch (RuntimeException e) { catch (RuntimeException e) {
// e.printStackTrace(); // e.printStackTrace();
@ -270,7 +272,9 @@ public class ApiClient {
} }
throw new ApiException( throw new ApiException(
response.getClientResponseStatus().getStatusCode(), response.getClientResponseStatus().getStatusCode(),
message); message,
response.getHeaders(),
respBody);
} }
} }

View File

@ -1,8 +1,13 @@
package io.swagger.client; package io.swagger.client;
import java.util.Map;
import java.util.List;
public class ApiException extends Exception { public class ApiException extends Exception {
int code = 0; private int code = 0;
String message = null; private String message = null;
private Map<String, List<String>> responseHeaders = null;
private String responseBody = null;
public ApiException() {} public ApiException() {}
@ -11,19 +16,42 @@ public class ApiException extends Exception {
this.message = message; 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() { public int getCode() {
return code; return code;
} }
public void setCode(int code) { public void setCode(int code) {
this.code = code; this.code = code;
} }
public String getMessage() { public String getMessage() {
return message; return message;
} }
public void setMessage(String message) { public void setMessage(String message) {
this.message = 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;
}
}