Skip to content

Commit

Permalink
Fix error constructor call in mapper adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
jianghaolu committed Sep 23, 2016
1 parent d67ca69 commit 163b389
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,11 @@ public ServiceResponse<T> build(Response<ResponseBody> response) throws E, IOExc
return new ServiceResponse<>((T) buildBody(statusCode, responseBody), response);
} else {
try {
Object errorBody = buildBody(statusCode, responseBody);
E exception = (E) exceptionType.getConstructor(String.class).newInstance(mapperAdapter.serialize(errorBody));
String responseContent = responseBody.string();
responseBody = ResponseBody.create(responseBody.contentType(), responseContent);
E exception = (E) exceptionType.getConstructor(String.class).newInstance(responseContent);
exceptionType.getMethod("setResponse", response.getClass()).invoke(exception, response);
exceptionType.getMethod("setBody", (Class<?>) responseTypes.get(0)).invoke(exception, errorBody);
exceptionType.getMethod("setBody", (Class<?>) responseTypes.get(0)).invoke(exception, buildBody(statusCode, responseBody));
throw exception;
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw new IOException("Invalid status code " + statusCode + ", but an instance of " + exceptionType.getCanonicalName()
Expand Down

0 comments on commit 163b389

Please sign in to comment.