def handle_result(callback): try: return callback.wait_for_completion() except pipeline_exceptions.ConnectionDroppedError as e: raise exceptions.ConnectionDroppedError( message="Lost connection to IoTHub", cause=e) except pipeline_exceptions.ConnectionFailedError as e: raise exceptions.ConnectionFailedError( message="Could not connect to IoTHub", cause=e) except pipeline_exceptions.NoConnectionError as e: raise exceptions.NoConnectionError( message="Client is not connected to IoTHub", cause=e) except pipeline_exceptions.UnauthorizedError as e: raise exceptions.CredentialError( message="Credentials invalid, could not connect", cause=e) except pipeline_exceptions.ProtocolClientError as e: raise exceptions.ClientError(message="Error in the IoTHub client", cause=e) except pipeline_exceptions.TlsExchangeAuthError as e: raise exceptions.ClientError( message="Error in the IoTHub client due to TLS exchanges.", cause=e) except pipeline_exceptions.ProtocolProxyError as e: raise exceptions.ClientError( message= "Error in the IoTHub client raised due to proxy connections.", cause=e) except pipeline_exceptions.PipelineNotRunning as e: raise exceptions.ClientError( message="Client has already been shut down", cause=e) except pipeline_exceptions.OperationCancelled as e: raise exceptions.OperationCancelled( message="Could not complete operation", cause=e) except Exception as e: raise exceptions.ClientError(message="Unexpected failure", cause=e)
async def handle_result(callback): try: return await callback.completion() except pipeline_exceptions.ConnectionDroppedError as e: raise exceptions.ConnectionDroppedError("Lost connection to IoTHub") from e except pipeline_exceptions.ConnectionFailedError as e: raise exceptions.ConnectionFailedError("Could not connect to IoTHub") from e except pipeline_exceptions.NoConnectionError as e: raise exceptions.NoConnectionError("Client is not connected to IoTHub") from e except pipeline_exceptions.UnauthorizedError as e: raise exceptions.CredentialError("Credentials invalid, could not connect") from e except pipeline_exceptions.ProtocolClientError as e: raise exceptions.ClientError("Error in the IoTHub client") from e except pipeline_exceptions.TlsExchangeAuthError as e: raise exceptions.ClientError("Error in the IoTHub client due to TLS exchanges.") from e except pipeline_exceptions.ProtocolProxyError as e: raise exceptions.ClientError( "Error in the IoTHub client raised due to proxy connections." ) from e except pipeline_exceptions.PipelineNotRunning as e: raise exceptions.ClientError("Client has already been shut down") from e except pipeline_exceptions.OperationCancelled as e: raise exceptions.OperationCancelled("Operation was cancelled before completion") from e except pipeline_exceptions.OperationTimeout as e: raise exceptions.OperationTimeout("Could not complete operation before timeout") from e except Exception as e: raise exceptions.ClientError("Unexpected failure") from e