Correct way to handle "AccessDenied" and other errors #1211
-
Hi there! I'm trying to write code that assumes a role and then goes on to perform various actions with that role (e.g. read from s3 bucket). It's pretty similar to the examples shown here: Since the user can provide a role that I don't have permissions to assume - I want to catch an "AccessDenied" error and handle it - print something informative to the user about not having permissions. Unfortunately, after looking at most examples online - I didn't see any way to properly handle it and access the error's code easily. Not by attempting to use The errors are a huge nested mess, and I honestly didn't understand how to get the access code - ugly code or not. I'd appreciate any help - thanks a lot! 🙏 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
While this isn't strictly a type-based approach, one way to determine if the returned service error is related to |
Beta Was this translation helpful? Give feedback.
While this isn't strictly a type-based approach, one way to determine if the returned service error is related to
AccessDenied
is by examining the DisplayErrorContext. These are examples in our repository showing how you can use it. You should then be able to search for an error string likeAccessDenied
.