feat: recreate sdk client with customized exception#1709
feat: recreate sdk client with customized exception#1709
Conversation
| private String getAccountId() { | ||
| return stsClient.getCallerIdentity(GetCallerIdentityRequest.builder().build()).account(); | ||
| return stsWrapper.execute(client -> | ||
| client.getCallerIdentity(GetCallerIdentityRequest.builder().build()).account()); |
There was a problem hiding this comment.
Recommendation generated by Amazon CodeGuru Reviewer. Leave feedback on this recommendation by replying to the comment or by reacting to the comment using emoji.
software.amazon.awssdk.services.sts.StsClient.getCallerIdentity API can also throw the following exception types: SdkClientException, StsException, SdkException, AwsServiceException, UnsupportedOperationException. We recommend handling these uncaught exceptions as well.
| private <R> R executeOperation(final Function<T, R> operation) { | ||
| try { | ||
| return operation.apply(client); | ||
| } catch (Exception e) { |
There was a problem hiding this comment.
Recommendation generated by Amazon CodeGuru Reviewer. Leave feedback on this recommendation by replying to the comment or by reacting to the comment using emoji.
It appears that your code handles a broad swath of exceptions in the catch block, potentially trapping dissimilar issues or problems that should not be dealt with at this point in the program.
| public <R> R execute(final Function<T, R> operation) { | ||
| try { | ||
| return executeOperation(operation); | ||
| } catch (Exception e) { |
There was a problem hiding this comment.
Recommendation generated by Amazon CodeGuru Reviewer. Leave feedback on this recommendation by replying to the comment or by reacting to the comment using emoji.
It appears that your code handles a broad swath of exceptions in the catch block, potentially trapping dissimilar issues or problems that should not be dealt with at this point in the program.
| if (client != null) { | ||
| try { | ||
| client.close(); | ||
| } catch (Exception e) { |
There was a problem hiding this comment.
Recommendation generated by Amazon CodeGuru Reviewer. Leave feedback on this recommendation by replying to the comment or by reacting to the comment using emoji.
It appears that your code handles a broad swath of exceptions in the catch block, potentially trapping dissimilar issues or problems that should not be dealt with at this point in the program.
| return executeOperation(operation); | ||
| } catch (Exception e) { | ||
| if (shouldRefreshClient(e)) { | ||
| System.out.println("Client needs refresh due to: " + e.getMessage()); |
There was a problem hiding this comment.
Recommendation generated by Amazon CodeGuru Reviewer. Leave feedback on this recommendation by replying to the comment or by reacting to the comment using emoji.
It appears that you are using println() rather than a dedicated logging facility makes it difficult to monitor the program behavior. We recommend to use a Java logging facility rather than System.out or System.err.
| try { | ||
| client.close(); | ||
| } catch (Exception e) { | ||
| System.err.println("Error closing client: " + e.getMessage()); |
There was a problem hiding this comment.
Recommendation generated by Amazon CodeGuru Reviewer. Leave feedback on this recommendation by replying to the comment or by reacting to the comment using emoji.
It appears that you are using println() rather than a dedicated logging facility makes it difficult to monitor the program behavior. We recommend to use a Java logging facility rather than System.out or System.err.
8b07086 to
35319f2
Compare
35319f2 to
a184a21
Compare
Issue #, if available:
Description of changes:
Why is this change necessary:
How was this change tested:
Any additional information or context required to review the change:
Documentation Checklist:
Compatibility Checklist:
any deprecated method or type.
Refer to Compatibility Guidelines for more information.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.