Skip to content

Commit

Permalink
block() function is not allowed to run in nio thread.
Browse files Browse the repository at this point in the history
use subscribe() to get string in non-blocking way.
  • Loading branch information
ivywei0125 committed Sep 16, 2022
1 parent af8a98c commit bb74188
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -105,19 +106,20 @@ protected String getCause(@Nonnull Throwable throwable) {
if (Objects.isNull(root)) {
return ExceptionUtils.getRootCause(throwable).toString();
}
String cause = null;
AtomicReference<String> cause = new AtomicReference<>(null);
if (root instanceof ManagementException) {
cause = Optional.of((ManagementException) root)
.map(ManagementException::getValue)
.map(ManagementError::getMessage)
.orElse("Unknown cause");
cause.set(Optional.of((ManagementException) root)
.map(ManagementException::getValue)
.map(ManagementError::getMessage)
.orElse("Unknown cause"));
} else if (root instanceof HttpResponseException) {
cause = Optional.of((HttpResponseException) root)
Optional.of((HttpResponseException) root)
.map(HttpResponseException::getResponse)
.map(HttpResponse::getBodyAsString)
.map(Mono::block).orElse("Unknown cause");
.orElse(Mono.just("Unknown cause"))
.subscribe(cause::set);
}
final String causeMsg = StringUtils.firstNonBlank(cause, root.getMessage());
final String causeMsg = StringUtils.firstNonBlank(cause.get(), root.getMessage());
return Optional.ofNullable(causeMsg)
.filter(StringUtils::isNotBlank)
.map(StringUtils::uncapitalize)
Expand Down

0 comments on commit bb74188

Please sign in to comment.