use of com.enonic.xp.portal.impl.error.PortalError in project xp by enonic.
the class ExceptionRendererImpl method doRenderCustomError.
private PortalResponse doRenderCustomError(final PortalRequest req, final WebException cause, final String handlerMethod) {
final PortalError portalError = PortalError.create().status(cause.getStatus()).message(cause.getMessage()).exception(cause).request(req).build();
final Site siteInRequest = req.getSite();
final Site site = siteInRequest != null ? siteInRequest : callAsContentAdmin(() -> this.contentService.findNearestSiteByPath(req.getContentPath()));
if (site != null) {
req.setSite(site);
try {
for (SiteConfig siteConfig : site.getSiteConfigs()) {
final ApplicationKey applicationKey = siteConfig.getApplicationKey();
for (final String scriptPath : SITE_ERROR_SCRIPT_PATHS) {
final PortalResponse response = renderApplicationCustomError(applicationKey, scriptPath, portalError, handlerMethod);
if (response != null) {
if (response.isPostProcess()) {
req.setApplicationKey(applicationKey);
}
return response;
}
}
}
} finally {
req.setSite(siteInRequest);
}
} else if (req.getApplicationKey() != null) {
final ApplicationKey applicationKey = req.getApplicationKey();
final PortalResponse response = renderApplicationCustomError(applicationKey, GENERIC_ERROR_SCRIPT_PATH, portalError, handlerMethod);
if (response != null) {
if (response.isPostProcess()) {
req.setApplicationKey(applicationKey);
}
return response;
}
}
return null;
}
Aggregations