@Test public void serverError() throws Exception { try { Future<Void> future = template.execute(baseUrl + "/status/server", HttpMethod.GET, null, null); future.get(); fail("HttpServerErrorException expected"); } catch (ExecutionException ex) { assertTrue(ex.getCause() instanceof HttpServerErrorException); HttpServerErrorException cause = (HttpServerErrorException)ex.getCause(); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, cause.getStatusCode()); assertNotNull(cause.getStatusText()); assertNotNull(cause.getResponseBodyAsString()); } }
@Override public void onFailure(Throwable ex) { assertTrue(ex instanceof HttpServerErrorException); HttpServerErrorException hsex = (HttpServerErrorException) ex; assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, hsex.getStatusCode()); assertNotNull(hsex.getStatusText()); assertNotNull(hsex.getResponseBodyAsString()); } });
@Test public void serverError() { try { template.execute(baseUrl + "/status/server", HttpMethod.GET, null, null); fail("HttpServerErrorException expected"); } catch (HttpServerErrorException ex) { assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, ex.getStatusCode()); assertNotNull(ex.getStatusText()); assertNotNull(ex.getResponseBodyAsString()); } }
if (MediaType.APPLICATION_JSON .includes(e.getResponseHeaders().getContentType())) { errorBody = e.getResponseBodyAsString();
@Test public void serverErrorCallbackWithLambdas() throws Exception { ListenableFuture<Void> future = template.execute(baseUrl + "/status/server", HttpMethod.GET, null, null); future.addCallback(result -> fail("onSuccess not expected"), ex -> { assertTrue(ex instanceof HttpServerErrorException); HttpServerErrorException hsex = (HttpServerErrorException) ex; assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, hsex.getStatusCode()); assertNotNull(hsex.getStatusText()); assertNotNull(hsex.getResponseBodyAsString()); }); waitTillDone(future); }
@Test public void shouldReturn500WhenSendingRequestWithAnyMethodToTheBookingIsDownService() { URI uri = UriComponentsBuilder.fromHttpUrl("http://www.booking-is-down.com") .path("/api/bookings/12345") .build() .toUri(); Throwable throwable = catchThrowable(() -> restTemplate.exchange(uri, HttpMethod.DELETE, null, Void.class)); assertThat(throwable).isInstanceOf(HttpServerErrorException.class); HttpServerErrorException exception = (HttpServerErrorException) throwable; // Then assertThat(exception.getStatusCode()).isEqualTo(INTERNAL_SERVER_ERROR); assertThat(exception.getResponseBodyAsString()).isEqualTo("booking is down"); }
throw new LinkedDataFetchingException(resourceURI, MessageFormat.format( "caught a HttpServerErrorException exception, for {0}. Underlying error message is: {1}, response Body: {2}", resourceURI, e.getMessage(), ((HttpServerErrorException) e).getResponseBodyAsString()), e);
String responseBody = ex.getResponseBodyAsString(); log.error( "Internal error happened during event data push: " + responseBody, ex );
@Test public void shouldFailToQueryBookingsIfUnexpectedQueryParamIsPresent() { // When URI uri = UriComponentsBuilder.fromHttpUrl("http://www.my-test.com") .path("/api/bookings/1") .queryParam("page", 1) .build() .toUri(); Throwable throwable = catchThrowable(() -> restTemplate.getForEntity(uri, SimpleBooking.class)); // Then assertThat(throwable).isInstanceOf(HttpServerErrorException.class); HttpServerErrorException exception = (HttpServerErrorException) throwable; assertThat(exception.getStatusCode()).isEqualTo(BAD_GATEWAY); assertThat(exception.getResponseBodyAsString()).containsIgnoringCase("Hoverfly error"); }
String responseBody = ex.getResponseBodyAsString(); log.error( "Internal error happened during completeness push: " + responseBody, ex ); throw ex;
String responseBody = ex.getResponseBodyAsString(); log.error( "Internal error happened during event data push: " + responseBody, ex ); throw ex;
String responseBody = ex.getResponseBodyAsString(); log.error( "Internal error happened during event data push: " + responseBody, ex ); throw ex;
String responseBody = ex.getResponseBodyAsString(); log.error( "Internal error happened during DataValues push: " + responseBody, ex );
if (MediaType.APPLICATION_JSON .includes(e.getResponseHeaders().getContentType())) { errorBody = e.getResponseBodyAsString();