Skip to content

Commit

Permalink
Only decorate in Dev Mode
Browse files Browse the repository at this point in the history
Signed-off-by: Phillip Kruger <phillip.kruger@gmail.com>
  • Loading branch information
phillip-kruger committed Jul 18, 2024
1 parent 11480d2 commit a56eff5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@ public class QuarkusErrorHandler implements Handler<RoutingContext> {
private static final AtomicLong ERROR_COUNT = new AtomicLong();

private final boolean showStack;
private final boolean decorateStack;
private final Optional<HttpConfiguration.PayloadHint> contentTypeDefault;

public QuarkusErrorHandler(boolean showStack, Optional<HttpConfiguration.PayloadHint> contentTypeDefault) {
public QuarkusErrorHandler(boolean showStack, boolean decorateStack,
Optional<HttpConfiguration.PayloadHint> contentTypeDefault) {
this.showStack = showStack;
this.decorateStack = decorateStack;
this.contentTypeDefault = contentTypeDefault;
}

Expand Down Expand Up @@ -129,7 +132,9 @@ public void accept(Throwable throwable) {
exception.addSuppressed(e);
}
if (showStack && exception != null) {
exception = new DecoratedAssertionError(exception);
if (decorateStack) {
exception = new DecoratedAssertionError(exception);
}
details = generateHeaderMessage(exception, uuid);
stack = generateStackTrace(exception);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,8 @@ public void finalizeRouter(BeanContainer container, Consumer<Route> defaultRoute

applyCompression(httpBuildTimeConfig.enableCompression, httpRouteRouter);
httpRouteRouter.route().last().failureHandler(
new QuarkusErrorHandler(launchMode.isDevOrTest(), httpConfiguration.unhandledErrorContentTypeDefault));
new QuarkusErrorHandler(launchMode.isDevOrTest(), launchMode.equals(LaunchMode.DEVELOPMENT),
httpConfiguration.unhandledErrorContentTypeDefault));

for (BooleanSupplier requireBodyHandlerCondition : requireBodyHandlerConditions) {
if (requireBodyHandlerCondition.getAsBoolean()) {
Expand Down Expand Up @@ -533,7 +534,8 @@ public void handle(RoutingContext event) {
addHotReplacementHandlerIfNeeded(mr);

mr.route().last().failureHandler(
new QuarkusErrorHandler(launchMode.isDevOrTest(), httpConfiguration.unhandledErrorContentTypeDefault));
new QuarkusErrorHandler(launchMode.isDevOrTest(), launchMode.equals(LaunchMode.DEVELOPMENT),
httpConfiguration.unhandledErrorContentTypeDefault));

mr.route().order(RouteConstants.ROUTE_ORDER_BODY_HANDLER_MANAGEMENT)
.handler(createBodyHandlerForManagementInterface());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public void string_with_quotes_should_be_correctly_escaped() {

@Test
public void json_content_type_hint_should_be_respected_if_not_accepted() {
QuarkusErrorHandler errorHandler = new QuarkusErrorHandler(false, Optional.of(HttpConfiguration.PayloadHint.JSON));
QuarkusErrorHandler errorHandler = new QuarkusErrorHandler(false, false,
Optional.of(HttpConfiguration.PayloadHint.JSON));
Mockito.when(routingContext.failure()).thenReturn(testError);
Mockito.when(routingContext.parsedHeaders().findBestUserAcceptedIn(any(), any()))
.thenReturn(new ParsableMIMEValue("application/foo+json").forceParse());
Expand All @@ -62,7 +63,8 @@ public void json_content_type_hint_should_be_respected_if_not_accepted() {

@Test
public void json_content_type_hint_should_be_ignored_if_accepted() {
QuarkusErrorHandler errorHandler = new QuarkusErrorHandler(false, Optional.of(HttpConfiguration.PayloadHint.JSON));
QuarkusErrorHandler errorHandler = new QuarkusErrorHandler(false, false,
Optional.of(HttpConfiguration.PayloadHint.JSON));
Mockito.when(routingContext.failure()).thenReturn(testError);
Mockito.when(routingContext.parsedHeaders().findBestUserAcceptedIn(any(), any()))
.thenReturn(new ParsableMIMEValue("text/html").forceParse());
Expand All @@ -73,7 +75,7 @@ public void json_content_type_hint_should_be_ignored_if_accepted() {

@Test
public void content_type_should_default_to_json_if_accepted() {
QuarkusErrorHandler errorHandler = new QuarkusErrorHandler(false, Optional.empty());
QuarkusErrorHandler errorHandler = new QuarkusErrorHandler(false, false, Optional.empty());
Mockito.when(routingContext.failure()).thenReturn(testError);
Mockito.when(routingContext.parsedHeaders().findBestUserAcceptedIn(any(), any()))
.thenReturn(new ParsableMIMEValue("application/json").forceParse());
Expand All @@ -84,7 +86,8 @@ public void content_type_should_default_to_json_if_accepted() {

@Test
public void html_content_type_hint_should_be_respected_if_not_accepted() {
QuarkusErrorHandler errorHandler = new QuarkusErrorHandler(false, Optional.of(HttpConfiguration.PayloadHint.HTML));
QuarkusErrorHandler errorHandler = new QuarkusErrorHandler(false, false,
Optional.of(HttpConfiguration.PayloadHint.HTML));
Mockito.when(routingContext.failure()).thenReturn(testError);
Mockito.when(routingContext.parsedHeaders().findBestUserAcceptedIn(any(), any()))
.thenReturn(new ParsableMIMEValue("application/foo+json").forceParse());
Expand All @@ -94,7 +97,8 @@ public void html_content_type_hint_should_be_respected_if_not_accepted() {

@Test
public void html_content_type_hint_should_be_ignored_if_accepted() {
QuarkusErrorHandler errorHandler = new QuarkusErrorHandler(false, Optional.of(HttpConfiguration.PayloadHint.HTML));
QuarkusErrorHandler errorHandler = new QuarkusErrorHandler(false, false,
Optional.of(HttpConfiguration.PayloadHint.HTML));
Mockito.when(routingContext.failure()).thenReturn(testError);
Mockito.when(routingContext.parsedHeaders().findBestUserAcceptedIn(any(), any()))
.thenReturn(new ParsableMIMEValue("application/json").forceParse());
Expand All @@ -105,7 +109,7 @@ public void html_content_type_hint_should_be_ignored_if_accepted() {

@Test
public void content_type_should_default_to_html_if_accepted() {
QuarkusErrorHandler errorHandler = new QuarkusErrorHandler(false, Optional.empty());
QuarkusErrorHandler errorHandler = new QuarkusErrorHandler(false, false, Optional.empty());
Mockito.when(routingContext.failure()).thenReturn(testError);
Mockito.when(routingContext.parsedHeaders().findBestUserAcceptedIn(any(), any()))
.thenReturn(new ParsableMIMEValue("text/html").forceParse());
Expand Down

0 comments on commit a56eff5

Please sign in to comment.