sorted.add(handler);
}
public void invoke(PipelineContext pipelineContext) throws Exception {
TurbineRunDataInternal rundata = (TurbineRunDataInternal) getTurbineRunData(request);
ErrorHandlerHelper helper = ErrorHandlerHelper.getInstance(request);
Throwable exception = helper.getException();
// 模板中可用的helper
rundata.getContext().put(helperName, helper);
if (exception != null) {
int statusCode = -1;
String target = null;
LoggingDetail loggingDetail = defaultLoggingDetail;
Logger logger = defaultLogger;
// 从最根本的exception cause开始反向追溯,例如:t1 caused by t2 caused by t3,
// 那么,检查顺序为t3, t2, t1。
CAUSES:
for (Throwable cause : getCauses(exception, true)) {
// 对于每个异常,查找匹配的exception handlers。
// 所有handlers已经排序,较特殊的异常在前,假设T1 extends T2,那么T1在T2之前。
for (ExceptionHandler exceptionHandler : exceptionHandlers) {
if (exceptionHandler.getExceptionType().isInstance(cause)) {
statusCode = exceptionHandler.getStatusCode();
target = exceptionHandler.getPage();
loggingDetail = exceptionHandler.getLoggingDetail();
logger = exceptionHandler.getLogger();
break CAUSES;
}
}
}
if (statusCode > 0) {
rundata.getResponse().setStatus(statusCode);
helper.setStatusCode(statusCode); // 更新request attributes
}
// 打印日志
helper.logError(logger, loggingDetail);
// 设定错误页面target
if (target == null) {
target = defaultPage;
}