/** * Returns a {@link RiposteUnhandledErrorHandler} that uses the given {@link ProjectApiErrors}. */ public static RiposteUnhandledErrorHandler defaultUnhandledErrorHandler(ProjectApiErrors projectApiErrors, ApiExceptionHandlerUtils utils) { return new RiposteUnhandledExceptionHandler(projectApiErrors, utils); }
/** * Returns a {@link RiposteErrorHandler} that uses the given {@link ProjectApiErrors}, and {@link * #defaultHandlerListeners(ProjectApiErrors, ApiExceptionHandlerUtils)} for the error handler listeners. */ public static RiposteErrorHandler defaultErrorHandler(ProjectApiErrors projectApiErrors, ApiExceptionHandlerUtils utils) { return new RiposteApiExceptionHandler( projectApiErrors, defaultHandlerListeners(projectApiErrors, utils), utils ); }
@Override public ErrorResponseInfo handleError(Throwable error, RequestInfo<?> requestInfo) { com.nike.backstopper.handler.ErrorResponseInfo<ErrorResponseBody> backstopperErrorResponseInfo = handleException(error, new RequestInfoForLoggingRiposteAdapter(requestInfo)); return new ErrorResponseInfoImpl(backstopperErrorResponseInfo); }
@Override public ErrorResponseInfo maybeHandleError(Throwable error, RequestInfo<?> requestInfo) throws UnexpectedMajorErrorHandlingError { try { com.nike.backstopper.handler.ErrorResponseInfo<ErrorResponseBody> backstopperErrorResponseInfo = maybeHandleException(error, new RequestInfoForLoggingRiposteAdapter(requestInfo)); if (backstopperErrorResponseInfo == null) return null; return new ErrorResponseInfoImpl(backstopperErrorResponseInfo); } catch (UnexpectedMajorExceptionHandlingError ex) { throw new UnexpectedMajorErrorHandlingError("Wrapping the actual cause", ex); } }
@Test(expected = IllegalArgumentException.class) public void constructorShouldBarfIfPassedNullProjectApiErrors() { new RiposteApiExceptionHandler(null, validListenerList, utils); }
@Test(expected = IllegalArgumentException.class) public void constructorThrowsIllegalArgumentExceptionIfPassedNullRequest() { new RequestInfoForLoggingRiposteAdapter(null); }
@Override public List<String> getHeaders(String headerName) { return getHeadersMap().get(headerName); }
@Test public void getQueryStringDelegatesToRequestInfo() { String expectedValue = UUID.randomUUID().toString(); setFieldOnRequestInfo("uri", "/some/path?" + expectedValue); assertThat(adapter.getQueryString(), is(expectedValue)); }
@Test public void getRequestUriDelegatesToRequestInfoPath() { String expectedValue = UUID.randomUUID().toString(); setFieldOnRequestInfo("path", expectedValue); assertThat(adapter.getRequestUri(), is(expectedValue)); }
@Test public void getRequestHttpMethodDelegatesToRequestInfo() { String expectedValue = UUID.randomUUID().toString(); setFieldOnRequestInfo("method", HttpMethod.valueOf(expectedValue)); assertThat(adapter.getRequestHttpMethod(), is(expectedValue)); }
@Test public void getHeaderDelegatesToRequestInfo() { String headerName = "someheader"; String expectedValue = UUID.randomUUID().toString(); HttpHeaders headersMock = mock(HttpHeaders.class); doReturn(expectedValue).when(headersMock).get(headerName); setFieldOnRequestInfo("headers", headersMock); assertThat(adapter.getHeader(headerName), is(expectedValue)); }
@Override protected ErrorResponseBody prepareFrameworkRepresentation( final DefaultErrorContractDTO errorContractDTO, final int httpStatusCode, final Collection<ApiError> rawFilteredApiErrors, final Throwable originalException, final RequestInfoForLogging request ) { Throwable cause = originalException.getCause(); if (cause instanceof BlankPayloadErrorContractException) { return handleBlankErrorContract(); } if (cause instanceof DelegatedErrorContractException) { return handleDelegatedErrorContract((DelegatedErrorContractException) originalException.getCause()); } if (cause instanceof StringErrorContractException) { return handleStringErrorContract((StringErrorContractException) originalException.getCause()); } return super.prepareFrameworkRepresentation(errorContractDTO, httpStatusCode, rawFilteredApiErrors, originalException, request); }
@Test public void getAttributeReturnsNull() { assertThat(adapter.getAttribute("someattribute"), nullValue()); }
@Test(expected = IllegalArgumentException.class) public void constructorShouldBarfIfPassedNullUtils() { new RiposteUnhandledExceptionHandler(projectApiErrors, null); }
@Test(expected = IllegalArgumentException.class) public void constructorShouldBarfIfPassedNullListenersList() { new RiposteApiExceptionHandler(projectApiErrors, null, utils); }
@Before public void beforeMethod() { requestInfoSpy = spy(new RequestInfoImpl(null, null, null, null, null, null, null, null, null, false, true, false)); adapter = new RequestInfoForLoggingRiposteAdapter(requestInfoSpy); }
@Test(expected = IllegalArgumentException.class) public void constructorShouldBarfIfPassedNullProjectApiErrors() { new RiposteUnhandledExceptionHandler(null, utils); }
@Test(expected = IllegalArgumentException.class) public void constructorShouldBarfIfPassedNullApiExceptionHandlerUtils() { new RiposteApiExceptionHandler(projectApiErrors, validListenerList, null); }
@Before public void beforeMethod() { adapterSpy = spy(new RiposteUnhandledExceptionHandler(projectApiErrors, utils)); }
@Before public void beforeMethod() { adapterSpy = spy(new RiposteApiExceptionHandler(projectApiErrors, validListenerList, utils)); }