@Test public void shouldThrowExceptionFor400PlusResponseStatus() throws Exception { Response response = mock(Response.class); when(response.getStatusCode()).thenReturn(123); when(response.to(String.class)).thenReturn("hello"); try { toTest.handle(response); fail(); } catch (CRestException e) { assertEquals("Response Status Code:123\nResponse: hello", e.getMessage()); } }
public Object handle(Response response) throws Exception { if(response.getStatusCode() >= minErrorStatusCode) { throw new CRestException("Response Status Code:" + response.getStatusCode() + "\nResponse: " + response.to(String.class)); } return response.deserialize(); }
DefaultResponseHandler implements ResponseHandler { public Object handle(Response response) throws Exception { if(response.getStatusCode() >= minErrorStatusCode) { throw new CRestException("Response Status Code:" + response.getStatusCode() + "\nResponse: " + response.to(String.class)); } return response.deserialize(); } }
DefaultResponseHandler implements ResponseHandler { public Object handle(Response response) throws Exception { if(response.getStatusCode() >= minErrorStatusCode) { throw new CRestException("Response Status Code:" + response.getStatusCode() + "\nResponse: " + response.to(String.class)); } return response.deserialize(); } DefaultResponseHandler(CRestConfig crestConfig); }
DefaultResponseHandler implements ResponseHandler { public Object handle(Response response) throws Exception { if(response.getStatusCode() >= minErrorStatusCode) { throw new CRestException("Response Status Code:" + response.getStatusCode() + "\nResponse: " + response.to(String.class)); } return response.deserialize(); } DefaultResponseHandler(CRestConfig crestConfig); Object handle(Response response); }
DefaultResponseHandler implements ResponseHandler { public Object handle(Response response) throws Exception { if(response.getStatusCode() >= minErrorStatusCode) { throw new CRestException("Response Status Code:" + response.getStatusCode() + "\nResponse: " + response.to(String.class)); } return response.deserialize(); } DefaultResponseHandler(CRestConfig crestConfig); Object handle(Response response); static final String MIN_ERROR_STATUS_CODE_PROP; }