Skip to content

Commit

Permalink
[SDCISA-13736, SDCISA-10974] Fix bad habits in ExpansionDeltaUtil.
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddenalpha committed Jan 4, 2024
1 parent ca605d1 commit 227d6b1
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();

Check warning on line 164 in gateleen-core/src/main/java/org/swisspush/gateleen/core/util/ExpansionDeltaUtil.java

View check run for this annotation

Codecov / codecov/patch

gateleen-core/src/main/java/org/swisspush/gateleen/core/util/ExpansionDeltaUtil.java#L163-L164

Added lines #L163 - L164 were not covered by tests
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());

Check warning on line 168 in gateleen-core/src/main/java/org/swisspush/gateleen/core/util/ExpansionDeltaUtil.java

View check run for this annotation

Codecov / codecov/patch

gateleen-core/src/main/java/org/swisspush/gateleen/core/util/ExpansionDeltaUtil.java#L167-L168

Added lines #L167 - L168 were not covered by tests
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);

Check warning on line 172 in gateleen-core/src/main/java/org/swisspush/gateleen/core/util/ExpansionDeltaUtil.java

View check run for this annotation

Codecov / codecov/patch

gateleen-core/src/main/java/org/swisspush/gateleen/core/util/ExpansionDeltaUtil.java#L170-L172

Added lines #L170 - L172 were not covered by tests
}
} 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());

Check warning on line 177 in gateleen-core/src/main/java/org/swisspush/gateleen/core/util/ExpansionDeltaUtil.java

View check run for this annotation

Codecov / codecov/patch

gateleen-core/src/main/java/org/swisspush/gateleen/core/util/ExpansionDeltaUtil.java#L176-L177

Added lines #L176 - L177 were not covered by tests
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);

Check warning on line 181 in gateleen-core/src/main/java/org/swisspush/gateleen/core/util/ExpansionDeltaUtil.java

View check run for this annotation

Codecov / codecov/patch

gateleen-core/src/main/java/org/swisspush/gateleen/core/util/ExpansionDeltaUtil.java#L179-L181

Added lines #L179 - L181 were not covered by tests
}
}
};
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());

Check warning on line 200 in gateleen-core/src/main/java/org/swisspush/gateleen/core/util/ExpansionDeltaUtil.java

View check run for this annotation

Codecov / codecov/patch

gateleen-core/src/main/java/org/swisspush/gateleen/core/util/ExpansionDeltaUtil.java#L198-L200

Added lines #L198 - L200 were not covered by tests
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);

Check warning on line 204 in gateleen-core/src/main/java/org/swisspush/gateleen/core/util/ExpansionDeltaUtil.java

View check run for this annotation

Codecov / codecov/patch

gateleen-core/src/main/java/org/swisspush/gateleen/core/util/ExpansionDeltaUtil.java#L202-L204

Added lines #L202 - L204 were not covered by tests
}
};
}
Expand Down

0 comments on commit 227d6b1

Please sign in to comment.