Skip to content

Commit

Permalink
Merge pull request #573 from swisspost/feature/handle_rest_storage_re…
Browse files Browse the repository at this point in the history
…sponses

Handle "Payload Too Large" responses from vertx-rest-storage
  • Loading branch information
mcweba authored May 2, 2024
2 parents 0b83c69 + d2ff185 commit 851c169
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public enum StatusCode {
GONE(410, "Gone"),
LENGTH_REQUIRED(411, "Length Required"),
PRECONDITION_FAILED(412, "Precondition Failed"),
CONTENT_TOO_LARGE(413, "Content Too Large"),
PAYLOAD_TOO_LARGE(413, "Payload Too Large"),
URI_TOO_LONG(414, "URI Too Long"),
UNSUPPORTED_MEDIA_TYPE(415, "Unsupported Media Type"),
RANGE_NOT_SATISFIABLE(416, "Range Not Satisfiable"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.concurrent.atomic.AtomicInteger;

import static org.swisspush.gateleen.core.util.StatusCode.INTERNAL_SERVER_ERROR;
import static org.swisspush.gateleen.core.util.StatusCode.PAYLOAD_TOO_LARGE;
import static org.swisspush.gateleen.routing.RuleFeatures.Feature.EXPAND_ON_BACKEND;
import static org.swisspush.gateleen.routing.RuleFeatures.Feature.STORAGE_EXPAND;
import static org.swisspush.gateleen.routing.RuleProvider.RuleChangesObserver;
Expand Down Expand Up @@ -544,7 +545,11 @@ private void makeStorageExpandRequest(final String targetUri, final List subReso
return;
}
cRes.bodyHandler(data -> {
if (StatusCode.INTERNAL_SERVER_ERROR.getStatusCode() == cRes.statusCode()) {
if (StatusCode.PAYLOAD_TOO_LARGE.getStatusCode() == cRes.statusCode()) {
String fullResponseBody = data.toString();
log.info("{}: {}: {}", PAYLOAD_TOO_LARGE, targetUri, fullResponseBody);
handler.handle(new ResourceNode(SERIOUS_EXCEPTION, new ResourceCollectionException(fullResponseBody, PAYLOAD_TOO_LARGE)));
} else if (StatusCode.INTERNAL_SERVER_ERROR.getStatusCode() == cRes.statusCode()) {
String fullResponseBody = data.toString();
log.error("{}: {}: {}", INTERNAL_SERVER_ERROR, targetUri, fullResponseBody);
handler.handle(new ResourceNode(SERIOUS_EXCEPTION, new ResourceCollectionException(fullResponseBody, StatusCode.INTERNAL_SERVER_ERROR)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ void handleResponseError(final HttpServerRequest req, final ResourceCollectionEx
ResponseStatusCodeLogUtil.debug(req, exception.getStatusCode(), RecursiveRootHandlerBase.class);
req.response().setStatusCode(exception.getStatusCode().getStatusCode());
req.response().setStatusMessage(exception.getStatusCode().getStatusMessage());
req.response().putHeader("Content-Type", "text/plain");
req.response().end(exception.getMessage());
}

Expand Down

0 comments on commit 851c169

Please sign in to comment.