use of lucee.runtime.err.ErrorPage in project Lucee by lucee.
the class PageContextImpl method handlePageException.
public void handlePageException(PageException pe, boolean setHeader) {
if (!Abort.isSilentAbort(pe)) {
// if(requestTimeoutException!=null)
// pe=Caster.toPageException(requestTimeoutException);
int statusCode = getStatusCode(pe);
// prepare response
if (rsp != null) {
// content-type
Charset cs = ReqRspUtil.getCharacterEncoding(this, rsp);
if (cs == null)
ReqRspUtil.setContentType(rsp, "text/html");
else
ReqRspUtil.setContentType(rsp, "text/html; charset=" + cs.name());
// expose error message in header
if (rsp != null && pe.getExposeMessage())
rsp.setHeader("exception-message", StringUtil.emptyIfNull(pe.getMessage()).replace('\n', ' '));
// status code
if (getConfig().getErrorStatusCode())
rsp.setStatus(statusCode);
}
ErrorPage ep = errorPagePool.getErrorPage(pe, ErrorPageImpl.TYPE_EXCEPTION);
// ExceptionHandler.printStackTrace(this,pe);
ExceptionHandler.log(getConfig(), pe);
// error page exception
if (ep != null) {
try {
Struct sct = pe.getErrorBlock(this, ep);
variablesScope().setEL(KeyConstants._error, sct);
variablesScope().setEL(KeyConstants._cferror, sct);
doInclude(new PageSource[] { ep.getTemplate() }, false);
return;
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
if (Abort.isSilentAbort(t))
return;
pe = Caster.toPageException(t);
}
}
// error page request
ep = errorPagePool.getErrorPage(pe, ErrorPageImpl.TYPE_REQUEST);
if (ep != null) {
PageSource ps = ep.getTemplate();
if (ps.physcalExists()) {
Resource res = ps.getResource();
try {
String content = IOUtil.toString(res, getConfig().getTemplateCharset());
Struct sct = pe.getErrorBlock(this, ep);
java.util.Iterator<Entry<Key, Object>> it = sct.entryIterator();
Entry<Key, Object> e;
String v;
while (it.hasNext()) {
e = it.next();
v = Caster.toString(e.getValue(), null);
if (v != null)
content = repl(content, e.getKey().getString(), v);
}
write(content);
return;
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
pe = Caster.toPageException(t);
}
} else
pe = new ApplicationException("The error page template for type request only works if the actual source file also exists. If the exception file is in an " + Constants.NAME + " archive (.lar), you need to use type exception instead.");
}
try {
String template = getConfig().getErrorTemplate(statusCode);
if (!StringUtil.isEmpty(template)) {
try {
Struct catchBlock = pe.getCatchBlock(getConfig());
variablesScope().setEL(KeyConstants._cfcatch, catchBlock);
variablesScope().setEL(KeyConstants._catch, catchBlock);
doInclude(template, false);
return;
} catch (PageException e) {
pe = e;
}
}
if (!Abort.isSilentAbort(pe))
forceWrite(getConfig().getDefaultDumpWriter(DumpWriter.DEFAULT_RICH).toString(this, pe.toDumpData(this, 9999, DumpUtil.toDumpProperties()), true));
} catch (Exception e) {
}
}
}
Aggregations