Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
  • Loading branch information
snicoll committed Jul 4, 2024
1 parent 06d267f commit 51641ec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,11 @@ public void setBodyDecodeFunction(Function<ResolvableType, ?> decoderFunction) {

@Override
public String getMessage() {
String message = String.valueOf(super.getMessage());
if (shouldHintAtResponseFailure()) {
return super.getMessage() + ", but response failed with cause: " + getCause();
return message + ", but response failed with cause: " + getCause();
}
return super.getMessage();
return message;
}

private boolean shouldHintAtResponseFailure() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@

import static org.assertj.core.api.Assertions.assertThat;

/**
* Tests for {@link WebClientResponseException}.
*
* @author Simon Baslé
*/
class WebClientResponseExceptionTests {

@Test
Expand All @@ -31,57 +36,58 @@ void constructWithSuccessStatusCodeAndNoCauseAdditionalMessage() {

@Test
void constructWith1xxStatusCodeAndCauseAdditionalMessage() {
final WebClientResponseException ex = new WebClientResponseException(100, "reasonPhrase", null, null, null);
WebClientResponseException ex = new WebClientResponseException(100, "reasonPhrase", null, null, null);
ex.initCause(new RuntimeException("example cause"));
assertThat(ex).hasMessage("100 reasonPhrase, but response failed with cause: java.lang.RuntimeException: example cause");
}

@Test
void constructWith2xxStatusCodeAndCauseAdditionalMessage() {
final WebClientResponseException ex = new WebClientResponseException(200, "reasonPhrase", null, null, null);
WebClientResponseException ex = new WebClientResponseException(200, "reasonPhrase", null, null, null);
ex.initCause(new RuntimeException("example cause"));
assertThat(ex).hasMessage("200 reasonPhrase, but response failed with cause: java.lang.RuntimeException: example cause");
}

@Test
void constructWith3xxStatusCodeAndCauseAdditionalMessage() {
final WebClientResponseException ex = new WebClientResponseException(300, "reasonPhrase", null, null, null);
WebClientResponseException ex = new WebClientResponseException(300, "reasonPhrase", null, null, null);
ex.initCause(new RuntimeException("example cause"));
assertThat(ex).hasMessage("300 reasonPhrase, but response failed with cause: java.lang.RuntimeException: example cause");
}

@Test
void constructWithExplicitMessageAndNotErrorCodeAdditionalMessage() {
final WebClientResponseException ex = new WebClientResponseException("explicit message", 100, "reasonPhrase", null, null, null);
WebClientResponseException ex = new WebClientResponseException("explicit message", 100, "reasonPhrase", null, null, null);
assertThat(ex).hasMessage("explicit message, but response failed with cause: null");
}

@Test
void constructWithExplicitMessageAndNotErrorCodeAndCauseAdditionalMessage() {
final WebClientResponseException ex = new WebClientResponseException("explicit message", 100, "reasonPhrase", null, null, null);
WebClientResponseException ex = new WebClientResponseException("explicit message", 100, "reasonPhrase", null, null, null);
ex.initCause(new RuntimeException("example cause"));
assertThat(ex).hasMessage("explicit message, but response failed with cause: java.lang.RuntimeException: example cause")
.hasRootCauseMessage("example cause");
}

@Test
void constructWithExplicitMessageAndErrorCodeAndCauseNoAdditionalMessage() {
final WebClientResponseException ex = new WebClientResponseException("explicit message", 404, "reasonPhrase", null, null, null);
WebClientResponseException ex = new WebClientResponseException("explicit message", 404, "reasonPhrase", null, null, null);
ex.initCause(new RuntimeException("example cause"));
assertThat(ex).hasMessage("explicit message").hasRootCauseMessage("example cause");
}

@Test
void constructWith4xxStatusCodeAndCauseNoAdditionalMessage() {
final WebClientResponseException ex = new WebClientResponseException(400, "reasonPhrase", null, null, null);
WebClientResponseException ex = new WebClientResponseException(400, "reasonPhrase", null, null, null);
ex.initCause(new RuntimeException("example cause"));
assertThat(ex).hasMessage("400 reasonPhrase").hasRootCauseMessage("example cause");
}

@Test
void constructWith5xxStatusCodeAndCauseNoAdditionalMessage() {
final WebClientResponseException ex = new WebClientResponseException(500, "reasonPhrase", null, null, null);
WebClientResponseException ex = new WebClientResponseException(500, "reasonPhrase", null, null, null);
ex.initCause(new RuntimeException("example cause"));
assertThat(ex).hasMessage("500 reasonPhrase").hasRootCauseMessage("example cause");
}

}

0 comments on commit 51641ec

Please sign in to comment.