is there any way to group all my exception cases into a single class?

You can group them in a tuple and use e.__class__.__name__ to get the exception name/type:

except (KeyError, FileExistsError) as e:
    log.info(e, exc_info=True)
    resp_dict = {'status': 'unsuccessful', 'message': e.__class__.__name__, 'data': ''}
    response = Response(response=json.dumps(resp_dict), status=400, mimetype='application/json',
                            headers=base_headers)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top