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;
}
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;
}
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());
}
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());
}
}
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());
}
}
Aggregations