Skip to content
Permalink
Browse files
De-uglified some twisted optional use.
  • Loading branch information
mifosio-04-04-2018 committed Jun 14, 2017
1 parent 5b7e04e commit 69fee9001e89b69e9e301cb5098bfc9613ed01a5
Showing 1 changed file with 4 additions and 10 deletions.
@@ -50,16 +50,16 @@ public AnnotatedErrorDecoder(final Logger logger, final Class feignClientClass)
public Exception decode(
final String methodKey,
final Response response) {
final Optional<Optional<Optional<Exception>>> ret =
final Optional<Exception> ret =
Arrays.stream(feignClientClass.getMethods())
.filter(method -> Feign.configKey(feignClientClass, method).equals(methodKey))
.map(method -> {
final Optional<ThrowsException> annotation = getMatchingAnnotation(response, method);
return annotation.map(a -> constructException(response, a));
return annotation.flatMap(a -> constructException(response, a));
})
.findAny();
.findAny().flatMap(x -> x);

return unwrapEmbeddedOptional(ret, getAlternative(methodKey, response));
return ret.orElse(getAlternative(methodKey, response));
}

private RuntimeException getAlternative(final String methodKey, final Response response) {
@@ -115,12 +115,6 @@ private boolean statusMatches(final Response response,
return throwsExceptionAnnotation.status().value() == response.status();
}

@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
private <T> T unwrapEmbeddedOptional(
final Optional<Optional<Optional<T>>> embeddedOptional, T alternative) {
return embeddedOptional.orElse(Optional.empty()).orElse(Optional.empty()).orElse(alternative);
}

private Optional<Exception> constructException(
final Response response,
final ThrowsException throwsExceptionAnnotations) {

0 comments on commit 69fee90

Please sign in to comment.