Skip to content

Commit

Permalink
documentation and error fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bd-g committed Aug 22, 2024
1 parent bf6dc9d commit fe7e71d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down
17 changes: 11 additions & 6 deletions src/listen/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use std::{
time::Duration,
};

use anyhow::anyhow;
use bytes::Bytes;
use futures::{
channel::mpsc::{self, Receiver, Sender},
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit fe7e71d

Please sign in to comment.