Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve exception unwrapping flexibility for SdkClientUtils #67

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dbwiddis
Copy link
Member

@dbwiddis dbwiddis commented Feb 5, 2025

Description

Adds the ability to unwrap from any of an optional list of exception types rather than just CompletionException.

So this usage:

Throwable t; // from the whenComplete() argument
Exception ex = SdkClientUtils.unwrapAndConvertToException(t, OpenSearchStatusException.class);

would unwrap the cause of an OpenSearchStatusException.

Issues Resolved

Allows keeping existing code based on IndexNotFoundException to remain unchanged.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@dbwiddis dbwiddis force-pushed the index-not-found branch 2 times, most recently from 6e3ded1 to 8f69d83 Compare February 5, 2025 17:15
@dbwiddis dbwiddis force-pushed the index-not-found branch 2 times, most recently from 37a6526 to 7b39494 Compare February 5, 2025 18:19
// Unwrap completion exception or pass through other exceptions
Throwable cause = throwable instanceof CompletionException ? throwable.getCause() : throwable;
@SafeVarargs
public static Exception unwrapAndConvertToException(Throwable throwable, Class<? extends Throwable>... exceptionTypesToUnwrap) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a new method which takes in exceptionTypesToUnwrap to ensure backward compatibility.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a varargs argument. It can be left blank, which is automatically creates an empty array, which is handled below with the default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants