HttpServletRequestWrapper extends HttpServerRequest { @Nullable Throwable maybeError() { Object maybeError = delegate.getAttribute("error"); if (maybeError instanceof Throwable) return (Throwable) maybeError; maybeError = delegate.getAttribute(RequestDispatcher.ERROR_EXCEPTION); if (maybeError instanceof Throwable) return (Throwable) maybeError; return null; } HttpServletRequestWrapper(HttpServletRequest delegate); static HttpServerRequest create(HttpServletRequest request); @Override final Object unwrap(); @Override boolean parseClientIpAndPort(Span span); @Override final String method(); @Override String route(); @Override final String path(); @Override String url(); @Override final String header(String name);  }
@Test public void maybeError_fromRequestAttribute() { Exception requestError = new Exception(); when(request.getAttribute("error")).thenReturn(requestError); assertThat(wrapper.maybeError()).isSameAs(requestError); }
@Test public void maybeError_badRequestAttribute() { when(request.getAttribute("error")).thenReturn(new Object()); assertThat(wrapper.maybeError()).isNull(); }
@Test public void maybeError_dispatcher() { Exception error = new Exception(); when(request.getAttribute(RequestDispatcher.ERROR_EXCEPTION)).thenReturn(error); assertThat(wrapper.maybeError()).isSameAs(error); }
@Test public void maybeError_dispatcher_badAttribute() { when(request.getAttribute(RequestDispatcher.ERROR_EXCEPTION)).thenReturn(new Object()); assertThat(wrapper.maybeError()).isNull(); }