Futures 0.3: idiomatic way to return errors in Streams

Hi, I was wondering what the idiomatic way is to handle the send and de-serialization errors in the following example. Do I basically turn the return type into Result<impl Stream<Item = (SubscriptionID, T), Error = ClientError>> or do I somehow return a stream with a single error response ... ? My goal is to replace the expects.

    pub async fn subscribe<T>(
        self,
        path: ActionPath,
        filters: Option<Filters>,
    ) -> impl Stream<Item = (SubscriptionID, T), Error = ClientError>
    where
        T: DeserializeOwned,
    {
        let (sink, stream) = self.client.split();

        let request_id = ReqID::default();
        let subscribe = Action::Subscribe {
            path,
            filters,
            request_id,
        };

        let subscribe_msg = serde_json::to_string(&subscribe).expect("Failed to serialize message");

        await!(sink.send(OwnedMessage::Text(subscribe_msg)).compat())
            .expect("Failed to send message");

        let subscription_id: Arc<Mutex<Option<SubscriptionID>>> = Default::default();

       stream
            .filter_map(move |msg| {
              //...
            }).map_err(Into::into)
}

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.