I have this problem when capturing the error:
try:
ack_event = PlatformEvent(
notification_event_id=event['detail']['originalEvent']['id'],
source=event['source'],
event_type=event['detail']['originalEvent']['detail']['eventType'],
region=event['region'],
timestamp=event['time'],
organization_id=self.get_notification_event_organization_id(event['detail']['originalEvent']),
success=event['detail']['success'],
result=event['detail']['result'],
event_json=event,
)
ack_event.save()
self.logger.info(f"Saved Acknowledgement Event: {event}")
return self.create_http_response(True, status_code=200)
except Exception as e:
msg_event = f"Error saving acknowledgement event: {event}"
msg_error = f"Error: {e}"
the message that I capture in the Exception as "e" if in the event that I receive there is a wrong property such as "originalEvent" the exception only captures the string "originalEvent" without detail of what the error is. Would there be a way to capture the error in more detail or what would I be doing wrong in this block? Thank you
Explanation
When you convert an error object to a string, you are only getting the message it shows you (not the traceback or the type of the error). If you want more details, I offer an alternative solution:
Alternative solution
To get all the error information in string form as if it had actually happened, we'll have to use a couple of modules from the standard library (sys and traceback).
sample code
Produces
Solution Explanation
Many processes happen here that I don't think it's a good idea to focus on explaining. But let's say what it does is print the currently handled exception (actual except clause) and send it to the sys.stdout file (which is where it sends the data, eg print).
References