From fe7e71d10f9d5ff5aa025088472b940b6a8d3aac Mon Sep 17 00:00:00 2001 From: Brent George Date: Thu, 22 Aug 2024 10:01:57 -0400 Subject: [PATCH] documentation and error fix --- src/lib.rs | 2 +- src/listen/websocket.rs | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index d11c95b5..ed1a21f3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -175,7 +175,7 @@ pub enum DeepgramError { /// A Deepgram API server response was not in the expected format. #[error("The Deepgram API server response was not in the expected format: {0}")] - UnexpectedServerResponse(String), + UnexpectedServerResponse(anyhow::Error), } #[cfg_attr(not(feature = "listen"), allow(unused))] diff --git a/src/listen/websocket.rs b/src/listen/websocket.rs index 4d064dd3..5f0b375f 100644 --- a/src/listen/websocket.rs +++ b/src/listen/websocket.rs @@ -18,6 +18,7 @@ use std::{ time::Duration, }; +use anyhow::anyhow; use bytes::Bytes; use futures::{ channel::mpsc::{self, Receiver, Sender}, @@ -676,15 +677,15 @@ impl<'a> WebsocketHandle { let request_id = upgrade_response .headers() .get("dg-request-id") - .ok_or(DeepgramError::UnexpectedServerResponse( - "Websocket upgrade headers missing request ID".to_string(), - ))? + .ok_or(DeepgramError::UnexpectedServerResponse(anyhow!( + "Websocket upgrade headers missing request ID" + )))? .to_str() .ok() .and_then(|req_header_str| Uuid::parse_str(req_header_str).ok()) - .ok_or(DeepgramError::UnexpectedServerResponse( - "Received malformed request ID in websocket upgrade headers".to_string(), - ))?; + .ok_or(DeepgramError::UnexpectedServerResponse(anyhow!( + "Received malformed request ID in websocket upgrade headers" + )))?; let (message_tx, message_rx) = mpsc::channel(256); let (response_tx, response_rx) = mpsc::channel(256); @@ -792,6 +793,10 @@ impl Stream for TranscriptionStream { } impl TranscriptionStream { + /// Returns the Deepgram request ID for the speech-to-text live request. + /// + /// A request ID needs to be provided to Deepgram as part of any support + /// or troubleshooting assistance related to a specific request. pub fn request_id(&self) -> Uuid { self.request_id }