Skip to content

Commit

Permalink
Merge pull request #537 from SDCISA-13736-FixBadHabits-ExpansionDelta…
Browse files Browse the repository at this point in the history
…Util
  • Loading branch information
hiddenalpha authored Jan 4, 2024
2 parents ca605d1 + 227d6b1 commit 466b022
Showing 1 changed file with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.vertx.core.MultiMap;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.core.json.DecodeException;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
Expand Down Expand Up @@ -159,26 +160,25 @@ public enum SlashHandling {
*/
public static Handler<Throwable> createRequestExceptionHandler(final HttpServerRequest request, final String uri, final Class<?> caller) {
return exception -> {
if (log.isTraceEnabled()) {
log.trace("end response with content");
}
log.trace("end response with content");
HttpServerResponse rsp = request.response();
if (exception instanceof TimeoutException) {
error("Timeout", request, uri, caller);
request.response().setStatusCode(StatusCode.TIMEOUT.getStatusCode());
request.response().setStatusMessage(StatusCode.TIMEOUT.getStatusMessage());
rsp.setStatusCode(StatusCode.TIMEOUT.getStatusCode());
rsp.setStatusMessage(StatusCode.TIMEOUT.getStatusMessage());
try {
request.response().end(request.response().getStatusMessage());
} catch (IllegalStateException e) {
// ignore because maybe already closed
rsp.end(rsp.getStatusMessage());
} catch (IllegalStateException ex) {
log.debug("ignore because maybe already closed", ex);
}
} else {
error(exception.getMessage(), request, uri, caller);
request.response().setStatusCode(StatusCode.SERVICE_UNAVAILABLE.getStatusCode());
request.response().setStatusMessage(StatusCode.SERVICE_UNAVAILABLE.getStatusMessage());
rsp.setStatusCode(StatusCode.SERVICE_UNAVAILABLE.getStatusCode());
rsp.setStatusMessage(StatusCode.SERVICE_UNAVAILABLE.getStatusMessage());
try {
request.response().end(request.response().getStatusMessage());
} catch (IllegalStateException e) {
// ignore because maybe already closed
rsp.end(rsp.getStatusMessage());
} catch (IllegalStateException ex) {
log.debug("ignore because maybe already closed", ex);
}
}
};
Expand All @@ -195,12 +195,13 @@ public static Handler<Throwable> createRequestExceptionHandler(final HttpServerR
public static Handler<Throwable> createResponseExceptionHandler(final HttpServerRequest request, final String uri, final Class<?> caller) {
return exception -> {
error("Problem with backend: " + exception.getMessage(), request, uri, caller);
request.response().setStatusCode(StatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
request.response().setStatusMessage(StatusCode.INTERNAL_SERVER_ERROR.getStatusMessage());
var rsp = request.response();
rsp.setStatusCode(StatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
rsp.setStatusMessage(StatusCode.INTERNAL_SERVER_ERROR.getStatusMessage());
try {
request.response().end(request.response().getStatusMessage());
} catch (IllegalStateException e) {
// ignore because maybe already closed
rsp.end(rsp.getStatusMessage());
} catch (IllegalStateException ex) {
log.debug("ignore because maybe already closed", ex);
}
};
}
Expand Down

0 comments on commit 466b022

Please sign in to comment.