def wrap_if_needed(exception): try: jsonpickle.loads(jsonpickle.dumps(exception)) return exception except BaseException: return _WrappedException(type(exception).__name__, str(exception))