Search in sources :

Example 1 with PortalError

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;
}
Also used : Site(com.enonic.xp.site.Site) ApplicationKey(com.enonic.xp.app.ApplicationKey) PortalResponse(com.enonic.xp.portal.PortalResponse) PortalError(com.enonic.xp.portal.impl.error.PortalError) SiteConfig(com.enonic.xp.site.SiteConfig)

Aggregations

ApplicationKey (com.enonic.xp.app.ApplicationKey)1 PortalResponse (com.enonic.xp.portal.PortalResponse)1 PortalError (com.enonic.xp.portal.impl.error.PortalError)1 Site (com.enonic.xp.site.Site)1 SiteConfig (com.enonic.xp.site.SiteConfig)1