BAEL-5378 Rename exceptions to avoid confusion (#11801)

This commit is contained in:
ashleyfrieze 2022-02-11 03:35:28 +00:00 committed by GitHub
parent 3ee3254ffb
commit a8a362dfcb
5 changed files with 20 additions and 20 deletions

View File

@ -1,7 +1,7 @@
package com.baeldung.webclient.status;
import com.baeldung.webclient.status.exception.BadRequestException;
import com.baeldung.webclient.status.exception.ServerErrorException;
import com.baeldung.webclient.status.exception.CustomBadRequestException;
import com.baeldung.webclient.status.exception.CustomServerErrorException;
import org.springframework.http.HttpStatus;
import org.springframework.web.reactive.function.client.ClientResponse;
import org.springframework.web.reactive.function.client.ExchangeFilterFunction;
@ -32,10 +32,10 @@ public class WebClientStatusCodeHandler {
.retrieve()
.onStatus(
HttpStatus.INTERNAL_SERVER_ERROR::equals,
response -> response.bodyToMono(String.class).map(ServerErrorException::new))
response -> response.bodyToMono(String.class).map(CustomServerErrorException::new))
.onStatus(
HttpStatus.BAD_REQUEST::equals,
response -> response.bodyToMono(String.class).map(BadRequestException::new))
response -> response.bodyToMono(String.class).map(CustomBadRequestException::new))
.bodyToMono(String.class);
}
@ -43,11 +43,11 @@ public class WebClientStatusCodeHandler {
HttpStatus status = response.statusCode();
if (HttpStatus.INTERNAL_SERVER_ERROR.equals(status)) {
return response.bodyToMono(String.class)
.flatMap(body -> Mono.error(new ServerErrorException(body)));
.flatMap(body -> Mono.error(new CustomServerErrorException(body)));
}
if (HttpStatus.BAD_REQUEST.equals(status)) {
return response.bodyToMono(String.class)
.flatMap(body -> Mono.error(new BadRequestException(body)));
.flatMap(body -> Mono.error(new CustomBadRequestException(body)));
}
return Mono.just(response);
}

View File

@ -1,7 +0,0 @@
package com.baeldung.webclient.status.exception;
public class BadRequestException extends Exception {
public BadRequestException(String message) {
super(message);
}
}

View File

@ -0,0 +1,7 @@
package com.baeldung.webclient.status.exception;
public class CustomBadRequestException extends Exception {
public CustomBadRequestException(String message) {
super(message);
}
}

View File

@ -0,0 +1,7 @@
package com.baeldung.webclient.status.exception;
public class CustomServerErrorException extends Exception {
public CustomServerErrorException(String message) {
super(message);
}
}

View File

@ -1,7 +0,0 @@
package com.baeldung.webclient.status.exception;
public class ServerErrorException extends Exception {
public ServerErrorException(String message) {
super(message);
}
}