Skip to content

Commit

Permalink
fix #84 REST client does not handle HTTP 204 properly
Browse files Browse the repository at this point in the history
  • Loading branch information
vegegoku committed Dec 10, 2023
1 parent d739114 commit 65e963a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.dominokit.rest.shared.request;

import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;

import java.util.Arrays;
Expand Down Expand Up @@ -119,14 +120,28 @@ private void handleResponse(
if (Arrays.stream(request.getSuccessCodes())
.anyMatch(code -> code.equals(response.getStatusCode()))) {
callSuccessGlobalHandlers(request, response);
callBack.onSuccess(request.getResponseReader().read(response));
callBack.onSuccess(readResponse(request, response));
} else {
FailedResponseBean failedResponse = new FailedResponseBean(request, response);
callFailedResponseHandlers(request, failedResponse);
callBack.onFailure(failedResponse);
}
}

private <R, S> S readResponse(ServerRequest<R, S> request, Response response) {
int statusCode = response.getStatusCode();
switch (statusCode) {
case 204:
{
if (isNull(response.getBodyAsString()) || response.getBodyAsString().isEmpty()) {
return null;
}
}
default:
return request.getResponseReader().read(response);
}
}

private void callSuccessGlobalHandlers(ServerRequest<R, S> request, Response response) {
DominoRestContext.make()
.getConfig()
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@

<gwt.version>2.10.0</gwt.version>
<domino.logger.version>1.0.3</domino.logger.version>
<domino.jackson.version>1.0.3</domino.jackson.version>
<domino.jackson.version>1.0.4</domino.jackson.version>
<domino.history.version>1.0.2</domino.history.version>
<domino.aggregator.version>1.0.2</domino.aggregator.version>
<jax.rs.version>2.1.1</jax.rs.version>
Expand Down

0 comments on commit 65e963a

Please sign in to comment.