Skip to content

Commit

Permalink
Merge pull request #42998 from phillip-kruger/error-page-prod-fix
Browse files Browse the repository at this point in the history
Error page and not found page now looks the same in prod mode
  • Loading branch information
phillip-kruger authored Sep 4, 2024
2 parents 17a2257 + 2e09518 commit 28f47d3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ public class TemplateHtmlBuilder {
" }\n" +
"</script>\n";

private static final String HTML_TEMPLATE_START_NO_STACK = "" +
"<!doctype html>\n" +
"<html lang=\"en\">\n" +
"<head>\n" +
" <title>%1$s%2$s</title>\n" +
" <meta charset=\"utf-8\">\n" +
"</head>";

private static final String HTML_TEMPLATE_START = "" +
"<!doctype html>\n" +
"<html lang=\"en\">\n" +
Expand Down Expand Up @@ -122,6 +130,10 @@ public class TemplateHtmlBuilder {
"</header>\n" +
"<div class=\"container content\">\n";

private static final String HEADER_TEMPLATE_NO_STACK = "<h1>%1$s</h1>\n" +
"%2$s \n" +
"<div class=\"container content\">\n";

private static final String RESOURCES_START = "<div class=\"intro\">%1$s</div><div class=\"resources\">";

private static final String ANCHOR_TEMPLATE_ABSOLUTE = "<a href=\"%1$s\">%2$s</a>";
Expand Down Expand Up @@ -185,37 +197,53 @@ public class TemplateHtmlBuilder {
private String baseUrl;

public TemplateHtmlBuilder(String title, String subTitle, String details) {
this(null, title, subTitle, details, Collections.emptyList(), null, Collections.emptyList());
this(true, null, title, subTitle, details, Collections.emptyList(), null, Collections.emptyList());
}

public TemplateHtmlBuilder(String title, String subTitle, String details, List<ErrorPageAction> actions) {
this(null, title, subTitle, details, actions, null, Collections.emptyList());
public TemplateHtmlBuilder(boolean showStack, String title, String subTitle, String details,
List<ErrorPageAction> actions) {
this(showStack, null, title, subTitle, details, actions, null, Collections.emptyList());
}

public TemplateHtmlBuilder(String baseUrl, String title, String subTitle, String details, List<ErrorPageAction> actions) {
this(baseUrl, title, subTitle, details, actions, null, Collections.emptyList());
public TemplateHtmlBuilder(String title, String subTitle, String details,
List<ErrorPageAction> actions) {
this(true, null, title, subTitle, details, actions, null, Collections.emptyList());
}

public TemplateHtmlBuilder(String title, String subTitle, String details, List<ErrorPageAction> actions, String redirect,
public TemplateHtmlBuilder(String baseUrl, String title, String subTitle, String details,
List<ErrorPageAction> actions) {
this(true, baseUrl, title, subTitle, details, actions, null, Collections.emptyList());
}

public TemplateHtmlBuilder(String title, String subTitle, String details, List<ErrorPageAction> actions,
String redirect,
List<CurrentConfig> config) {
this(null, title, subTitle, details, actions, null, Collections.emptyList());
this(true, null, title, subTitle, details, actions, null, Collections.emptyList());
}

public TemplateHtmlBuilder(String baseUrl, String title, String subTitle, String details, List<ErrorPageAction> actions,
public TemplateHtmlBuilder(boolean showStack, String baseUrl, String title, String subTitle, String details,
List<ErrorPageAction> actions,
String redirect,
List<CurrentConfig> config) {
this.baseUrl = baseUrl;
StringBuilder actionLinks = new StringBuilder();

loadCssFile();
if (showStack) {
loadCssFile();
for (ErrorPageAction epa : actions) {
actionLinks.append(buildLink(epa.name(), epa.url()));
}

StringBuilder actionLinks = new StringBuilder();
for (ErrorPageAction epa : actions) {
actionLinks.append(buildLink(epa.name(), epa.url()));
result = new StringBuilder(String.format(HTML_TEMPLATE_START, escapeHtml(title),
subTitle == null || subTitle.isEmpty() ? "" : " - " + escapeHtml(subTitle), CSS));
result.append(String.format(HEADER_TEMPLATE, escapeHtml(title), escapeHtml(details), actionLinks.toString()));
} else {
result = new StringBuilder(String.format(HTML_TEMPLATE_START_NO_STACK, escapeHtml(title),
subTitle == null || subTitle.isEmpty() ? "" : " - " + escapeHtml(subTitle), CSS));
result.append(
String.format(HEADER_TEMPLATE_NO_STACK, escapeHtml(title), escapeHtml(details), actionLinks.toString()));
}

result = new StringBuilder(String.format(HTML_TEMPLATE_START, escapeHtml(title),
subTitle == null || subTitle.isEmpty() ? "" : " - " + escapeHtml(subTitle), CSS));
result.append(String.format(HEADER_TEMPLATE, escapeHtml(title), escapeHtml(details), actionLinks.toString()));
if (!config.isEmpty()) {
result.append(String.format(CONFIG_EDITOR_HEAD, redirect));
for (CurrentConfig i : config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ private void jsonResponse(RoutingContext event, String contentType, String detai

private void htmlResponse(RoutingContext event, String details, Throwable exception) {
event.response().headers().set(HttpHeaderNames.CONTENT_TYPE, "text/html; charset=utf-8");
final TemplateHtmlBuilder htmlBuilder = new TemplateHtmlBuilder("Internal Server Error", details, details,
final TemplateHtmlBuilder htmlBuilder = new TemplateHtmlBuilder(showStack, "Internal Server Error", details, details,
this.actions);

if (decorateStack && exception != null) {
Expand Down

0 comments on commit 28f47d3

Please sign in to comment.