use of com.blade.mvc.ui.HtmlCreator in project blade by biezhi.
the class DefaultExceptionHandler method handleBladeException.
protected void handleBladeException(BladeException e, Request request, Response response) {
var blade = WebContext.blade();
response.status(e.getStatus());
var modelAndView = new ModelAndView();
modelAndView.add("title", e.getStatus() + " " + e.getName());
modelAndView.add("message", e.getMessage());
if (null != e.getCause()) {
request.attribute(VARIABLE_STACKTRACE, getStackTrace(e));
}
if (e.getStatus() == InternalErrorException.STATUS) {
log.error("", e);
this.render500(request, response);
}
String paddingMethod = BladeCache.getPaddingMethod(request.method());
if (e.getStatus() == NotFoundException.STATUS) {
log404(log, paddingMethod, request.uri());
if (request.isJsonRequest()) {
response.json(RestResponse.fail(NotFoundException.STATUS, "Not Found [" + request.uri() + "]"));
} else {
var page404 = Optional.ofNullable(blade.environment().get(ENV_KEY_PAGE_404, null));
if (page404.isPresent()) {
modelAndView.setView(page404.get());
renderPage(response, modelAndView);
response.render(page404.get());
} else {
HtmlCreator htmlCreator = new HtmlCreator();
htmlCreator.center("<h1>404 Not Found - " + request.uri() + "</h1>");
htmlCreator.hr();
response.html(htmlCreator.html());
}
}
}
if (e.getStatus() == MethodNotAllowedException.STATUS) {
log405(log, paddingMethod, request.uri());
if (request.isJsonRequest()) {
response.json(RestResponse.fail(MethodNotAllowedException.STATUS, e.getMessage()));
} else {
response.text(e.getMessage());
}
}
}
use of com.blade.mvc.ui.HtmlCreator in project blade by biezhi.
the class DefaultExceptionHandler method render500.
protected void render500(Request request, Response response) {
var blade = WebContext.blade();
var page500 = Optional.ofNullable(blade.environment().get(ENV_KEY_PAGE_500, null));
if (page500.isPresent()) {
this.renderPage(response, new ModelAndView(page500.get()));
} else {
if (blade.devMode()) {
var htmlCreator = new HtmlCreator();
htmlCreator.center("<h1>" + request.attribute("title") + "</h1>");
htmlCreator.startP("message-header");
htmlCreator.add("Request URI: " + request.uri());
htmlCreator.startP("message-header");
htmlCreator.add("Error Message: " + request.attribute("message"));
htmlCreator.endP();
if (null != request.attribute(VARIABLE_STACKTRACE)) {
htmlCreator.startP("message-body");
htmlCreator.add(request.attribute(VARIABLE_STACKTRACE).toString().replace("\n", "<br/>"));
htmlCreator.endP();
}
response.html(htmlCreator.html());
} else {
response.html(INTERNAL_SERVER_ERROR_HTML);
}
}
}
Aggregations