I am using RDSDataService in a lambda to execute queries in an Aurora Serverless DB. It's all good when everything runs fine, but when there is an error running the query I get something like this
An error occurred (BadRequestException) when calling the ExecuteStatement operation: ERROR: duplicate key value violates unique constraint "user_role_role_name_key" Detail: Key (role_name)=(Test3 ) already exists.
I am catching that using a generic except Exception as e
and then printing e
.
Questions:
- What package do I need to import to catch BadRequestException
- How would I parse it to extract the detail part?