if (context != null && AjaxUtils.isAjaxRequest(context.request())) {
ERXRedirect redirect = pageWithName(ERXRedirect.class, context);
redirect.setDirectActionName("error");
response = redirect.generateResponse();
} else {
SPErrorPage errorPage = pageWithName(SPErrorPage.class, context);
errorPage.setException(exception);
response = errorPage.generateResponse();
}
return response;
}