Search in sources :

Example 1 with HttpStatus

use of com.enonic.xp.web.HttpStatus in project xp by enonic.

the class ExceptionRendererImpl method render.

@Override
public PortalResponse render(final WebRequest webRequest, final WebException cause) {
    String tip = null;
    final ExceptionInfo info = toErrorInfo(cause);
    logIfNeeded(info);
    if (webRequest instanceof PortalRequest) {
        PortalRequest portalRequest = (PortalRequest) webRequest;
        final HttpStatus httpStatus = cause.getStatus();
        if (httpStatus != null) {
            final String handlerMethod = "handle" + httpStatus.value();
            final PortalResponse statusCustomError = renderCustomError(portalRequest, cause, handlerMethod);
            if (statusCustomError != null) {
                logIfNeeded(toErrorInfo(cause));
                return statusCustomError;
            }
        }
        final PortalResponse idProviderError = renderIdProviderError(portalRequest, cause);
        if (idProviderError != null) {
            logIfNeeded(toErrorInfo(cause));
            return idProviderError;
        }
        final PortalResponse defaultCustomError = renderCustomError(portalRequest, cause, DEFAULT_HANDLER);
        if (defaultCustomError != null) {
            logIfNeeded(toErrorInfo(cause));
            return defaultCustomError;
        }
        if ("/site".equals(portalRequest.getBaseUri()) && ContentConstants.BRANCH_MASTER.equals(portalRequest.getBranch()) && HttpStatus.NOT_FOUND.equals(cause.getStatus())) {
            tip = "Tip: Did you remember to publish the site?";
        }
    }
    return renderInternalErrorPage(webRequest, tip, cause);
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) HttpStatus(com.enonic.xp.web.HttpStatus) PortalRequest(com.enonic.xp.portal.PortalRequest)

Example 2 with HttpStatus

use of com.enonic.xp.web.HttpStatus in project xp by enonic.

the class ExceptionMapperImpl method throwIfNeeded.

@Override
public void throwIfNeeded(final WebResponse res) throws WebException {
    final HttpStatus status = res.getStatus();
    final Object body = res.getBody();
    if (isError(status) && (body == null)) {
        throw new WebException(status, status.getReasonPhrase());
    }
}
Also used : WebException(com.enonic.xp.web.WebException) HttpStatus(com.enonic.xp.web.HttpStatus)

Aggregations

HttpStatus (com.enonic.xp.web.HttpStatus)2 PortalRequest (com.enonic.xp.portal.PortalRequest)1 PortalResponse (com.enonic.xp.portal.PortalResponse)1 WebException (com.enonic.xp.web.WebException)1