+ .verify();
+
+
+ server
+ .enqueue(new MockResponse()
+ .setResponseCode(HttpStatus.INTERNAL_SERVER_ERROR.value())
+ .setHeader("Content-Type", "text/plain")
+ .setBody("Hallo Welt!"));
+
+ result =
+ webClient
+ .get()
+ .uri("/egal")
+ .retrieve()
+ .bodyToMono(String.class);
+
+ StepVerifier
+ .create(result)
+ .expectError(InternalServerError.class)
+ .verify();
+ }
+
+ @Test
+ public void testValidError()
+ {
+ server
+ .enqueue(new MockResponse()
+ .setResponseCode(HttpStatus.BAD_REQUEST.value())
+ .setHeader("Content-Type", "application/json")
+ .setBody(
+ "{\n" +
+ " \"error\":\n" +
+ " {\n" +
+ " \"message\": \"(#613) Calls to stream have exceeded the rate of 600 calls per 600 seconds.\",\n" +
+ " \"type\": \"OAuthException\",\n" +
+ " \"code\": 613\n" +
+ " }\n" +
+ "}"));
+
+ Mono<String> result =
+ webClient
+ .get()
+ .uri("/egal")
+ .retrieve()
+ .bodyToMono(String.class);
+
+ StepVerifier.create(result).expectErrorSatisfies(throwable ->
+ {
+ assertEquals(RateLimitExceededException.class, throwable.getClass());
+ RateLimitExceededException e = (RateLimitExceededException)throwable;
+ LOG.debug("{}", e.toString());
+ assertEquals(new Integer(613), e.getCode());
+ assertEquals("(#613) Calls to stream have exceeded the rate of 600 calls per 600 seconds.", e.getMessage());
+ assertEquals(Type.OAuthException, e.getType());
+ })
+ .verify();
+ }
+
+ @Test
+ public void testUnmappedError()
+ {
+ server
+ .enqueue(new MockResponse()
+ .setResponseCode(HttpStatus.BAD_REQUEST.value())
+ .setHeader("Content-Type", "application/json")
+ .setBody(
+ "{\n" +
+ " \"error\":\n" +
+ " {\n" +
+ " \"message\": \"This error does not exist.\",\n" +
+ " \"type\": \"NonexistentTypeException\",\n" +
+ " \"code\": 999999999\n" +
+ " }\n" +
+ "}"));
+
+
+ Mono<String> result =
+ webClient
+ .get()
+ .uri("/egal")
+ .retrieve()
+ .bodyToMono(String.class);
+
+ StepVerifier.create(result).expectErrorSatisfies(throwable ->
+ {
+ assertEquals(UnmappedErrorException.class, throwable.getClass());
+ UnmappedErrorException e = (UnmappedErrorException)throwable;
+ LOG.debug("{}", e.toString());
+ assertEquals(new Integer(999999999), e.getCode());
+ assertEquals("This error does not exist.", e.getMessage());
+ try
+ {
+ Type type = e.getType();
+ LOG.error("unknown type: {}", type);
+ fail("unmapped type was resolved by enum: " + type);
+ }
+ catch (IllegalArgumentException ee) {}
+ })
+ .verify();
+ }
+
+ @Test
+ public void testInvlalidError()
+ {
+ Mono<String> result;
+
+
+ server
+ .enqueue(new MockResponse()
+ .setResponseCode(HttpStatus.BAD_REQUEST.value())
+ .setHeader("Content-Type", "application/json")
+ .setBody(
+ "{\n" +
+ " \"error\":\n" +
+ " {\n" +
+ " \"message\": \"Not a Graph-Api-Exception.\",\n" +
+ " \"type\": \"Whatever\",\n" +
+ " \"code\": \"some string\"\n" +
+ " }\n" +
+ "}"));
+
+ result =
+ webClient
+ .get()
+ .uri("/egal")
+ .retrieve()
+ .bodyToMono(String.class);
+
+ StepVerifier.create(result).expectError(BadRequest.class).verify();
+
+
+ server
+ .enqueue(new MockResponse()
+ .setResponseCode(HttpStatus.BAD_REQUEST.value())
+ .setHeader("Content-Type", "text/plain")
+ .setBody("Hallo Welt!"));
+
+ result =
+ webClient
+ .get()
+ .uri("/egal")
+ .retrieve()
+ .bodyToMono(String.class);