Search in sources :

Example 1 with WebException

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

the class BasePortalHandler method handleError.

private WebResponse handleError(final WebRequest webRequest, final Exception e) {
    final WebException webException = exceptionMapper.map(e);
    final WebResponse webResponse = exceptionRenderer.render(webRequest, webException);
    webRequest.getRawRequest().setAttribute("error.handled", Boolean.TRUE);
    return webResponse;
}
Also used : WebException(com.enonic.xp.web.WebException) WebResponse(com.enonic.xp.web.WebResponse)

Example 2 with WebException

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

the class WebAppHandler method handleError.

private WebResponse handleError(final WebRequest webRequest, final Exception e) {
    final WebException webException = exceptionMapper.map(e);
    final WebResponse webResponse = exceptionRenderer.render(webRequest, webException);
    webRequest.getRawRequest().setAttribute("error.handled", Boolean.TRUE);
    return webResponse;
}
Also used : WebException(com.enonic.xp.web.WebException) WebResponse(com.enonic.xp.web.WebResponse)

Example 3 with WebException

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

the class ContentResolverTest method resolve_non_existing_in_live_mode.

@Test
void resolve_non_existing_in_live_mode() {
    final Site site = newSite();
    final PortalRequest request = new PortalRequest();
    final ContentPath contentPath = ContentPath.from("/mysite/landing-page/non-existing");
    request.setContentPath(contentPath);
    when(this.contentService.getByPath(contentPath)).thenThrow(new ContentNotFoundException(contentPath, null));
    when(this.contentService.contentExists(contentPath)).thenReturn(false);
    when(this.contentService.findNearestSiteByPath(contentPath)).thenReturn(site);
    final ContentResolverResult result = new ContentResolver(contentService).resolve(request);
    assertNull(result.getContent());
    assertSame(site, result.getNearestSite());
    assertEquals("/landing-page/non-existing", result.getSiteRelativePath());
    final WebException e = assertThrows(WebException.class, result::getContentOrElseThrow);
    assertEquals(HttpStatus.NOT_FOUND, e.getStatus());
}
Also used : Site(com.enonic.xp.site.Site) WebException(com.enonic.xp.web.WebException) ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) ContentPath(com.enonic.xp.content.ContentPath) PortalRequest(com.enonic.xp.portal.PortalRequest) Test(org.junit.jupiter.api.Test)

Example 4 with WebException

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

the class FilterScriptImplTest method testNoFilterFunction.

@Test
public void testNoFilterFunction() throws Exception {
    WebHandlerChain webHandlerChain = Mockito.mock(WebHandlerChain.class);
    Mockito.when(webHandlerChain.handle(Mockito.any(), Mockito.any())).thenReturn(this.portalResponse);
    this.portalRequest.setMethod(HttpMethod.POST);
    try {
        execute("myapplication:/filter/nofilter.js", webHandlerChain);
        fail("Expected exception");
    } catch (WebException e) {
        assertEquals("Missing exported function 'filter' in filter script: myapplication:/filter/nofilter.js", e.getMessage());
    }
}
Also used : WebException(com.enonic.xp.web.WebException) WebHandlerChain(com.enonic.xp.web.handler.WebHandlerChain) Test(org.junit.jupiter.api.Test)

Example 5 with WebException

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

the class ExceptionMapperTest method assertThrowIfNeeded.

private void assertThrowIfNeeded(final HttpStatus status) {
    final PortalResponse response = PortalResponse.create().status(status).build();
    try {
        this.mapper.throwIfNeeded(response);
        fail("Should throw exception");
    } catch (final WebException e) {
        assertEquals(status, e.getStatus());
    }
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) WebException(com.enonic.xp.web.WebException)

Aggregations

WebException (com.enonic.xp.web.WebException)47 Test (org.junit.jupiter.api.Test)39 PortalResponse (com.enonic.xp.portal.PortalResponse)14 ContentPath (com.enonic.xp.content.ContentPath)12 Site (com.enonic.xp.site.Site)10 PortalRequest (com.enonic.xp.portal.PortalRequest)8 BaseHandlerTest (com.enonic.xp.web.handler.BaseHandlerTest)7 ContentNotFoundException (com.enonic.xp.content.ContentNotFoundException)6 HttpStatus (com.enonic.xp.web.HttpStatus)5 MediaType (com.google.common.net.MediaType)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 ApplicationKey (com.enonic.xp.app.ApplicationKey)4 Branch (com.enonic.xp.branch.Branch)4 Content (com.enonic.xp.content.Content)4 ContentId (com.enonic.xp.content.ContentId)4 ContentService (com.enonic.xp.content.ContentService)4 PropertyTree (com.enonic.xp.data.PropertyTree)4 RenderMode (com.enonic.xp.portal.RenderMode)4 ErrorHandlerScript (com.enonic.xp.portal.impl.error.ErrorHandlerScript)4 ErrorHandlerScriptFactory (com.enonic.xp.portal.impl.error.ErrorHandlerScriptFactory)4