Skip to content

Commit 2142f68

Browse files
committed
feat: update version to 0.2.54 and enhance error handling with status codes
1 parent 20d9793 commit 2142f68

File tree

11 files changed

+32
-40
lines changed

11 files changed

+32
-40
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rsipstack"
3-
version = "0.2.53"
3+
version = "0.2.54"
44
edition = "2021"
55
description = "SIP Stack Rust library for building SIP applications"
66
license = "MIT"

src/bin/bench_ua.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,14 +284,12 @@ async fn process_dialog_state(
284284
}
285285
DialogState::Terminated(id, status) => {
286286
match status {
287-
TerminatedReason::UacOther(Some(status)) => {
287+
TerminatedReason::UacOther(status) => {
288288
info!("dialog terminated with status: {}", status);
289289
}
290-
TerminatedReason::UasOther(Some(status)) => {
290+
TerminatedReason::UasOther(status) => {
291291
info!("dialog terminated with status: {}", status);
292292
}
293-
TerminatedReason::UacOther(None) => {}
294-
TerminatedReason::UasOther(None) => {}
295293
_ => {}
296294
}
297295
dialog_layer.remove_dialog(&id);

src/dialog/authenticate.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,12 @@ pub async fn handle_client_authenticate(
194194
let header = match resp.www_authenticate_header() {
195195
Some(h) => Header::WwwAuthenticate(h.clone()),
196196
None => {
197+
let code = resp.status_code.clone();
197198
let proxy_header = rsip::header_opt!(resp.headers().iter(), Header::ProxyAuthenticate);
198199
let proxy_header = proxy_header.ok_or(crate::Error::DialogError(
199200
"missing proxy/www authenticate".to_string(),
200201
DialogId::try_from(&tx.original)?,
202+
code,
201203
))?;
202204
Header::ProxyAuthenticate(proxy_header.clone())
203205
}

src/dialog/client_dialog.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ impl ClientInviteDialog {
420420
return Err(crate::Error::DialogError(
421421
"invalid request".to_string(),
422422
self.id(),
423+
rsip::StatusCode::MethodNotAllowed,
423424
));
424425
}
425426
}
@@ -562,15 +563,20 @@ impl ClientInviteDialog {
562563
break;
563564
}
564565
_ => {
565-
let mut reason = format!("{}", resp.status_code);
566-
if let Some(reason_phrase) = resp.reason_phrase() {
567-
reason = format!("{};{}", reason, reason_phrase);
568-
}
566+
let reason = if let Some(reason_phrase) = resp.reason_phrase() {
567+
format!("{reason_phrase}")
568+
} else {
569+
format!("{}", resp.status_code)
570+
};
569571
self.inner.transition(DialogState::Terminated(
570572
self.id(),
571-
TerminatedReason::UasOther(Some(resp.status_code.clone())),
573+
TerminatedReason::UasOther(resp.status_code.clone()),
572574
))?;
573-
return Err(crate::Error::DialogError(reason, self.id()));
575+
return Err(crate::Error::DialogError(
576+
reason,
577+
self.id(),
578+
resp.status_code,
579+
));
574580
}
575581
}
576582
}

src/dialog/dialog.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ pub enum TerminatedReason {
9292
UasDecline,
9393
ProxyError(rsip::StatusCode),
9494
ProxyAuthRequired,
95-
UacOther(Option<rsip::StatusCode>),
96-
UasOther(Option<rsip::StatusCode>),
95+
UacOther(rsip::StatusCode),
96+
UasOther(rsip::StatusCode),
9797
}
9898

9999
/// SIP Dialog

src/dialog/dialog_layer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ impl DialogLayer {
160160
return Err(crate::Error::DialogError(
161161
"the dialog not found".to_string(),
162162
id,
163+
rsip::StatusCode::CallTransactionDoesNotExist,
163164
));
164165
}
165166
}

src/dialog/registration.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ impl Registration {
488488
return Err(crate::Error::DialogError(
489489
"registration transaction is already terminated".to_string(),
490490
DialogId::try_from(&tx.original)?,
491+
StatusCode::BadRequest,
491492
));
492493
}
493494

src/dialog/server_dialog.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,7 @@ impl ServerInviteDialog {
593593
return Err(crate::Error::DialogError(
594594
"invalid request in confirmed state".to_string(),
595595
self.id(),
596+
rsip::StatusCode::MethodNotAllowed,
596597
));
597598
}
598599
rsip::Method::Bye => return self.handle_bye(tx).await,
@@ -605,6 +606,7 @@ impl ServerInviteDialog {
605606
return Err(crate::Error::DialogError(
606607
"invalid request".to_string(),
607608
self.id(),
609+
rsip::StatusCode::MethodNotAllowed,
608610
));
609611
}
610612
}
@@ -721,6 +723,7 @@ impl TryFrom<&Dialog> for ServerInviteDialog {
721723
_ => Err(crate::Error::DialogError(
722724
"Dialog is not a ServerInviteDialog".to_string(),
723725
dlg.id(),
726+
rsip::StatusCode::BadRequest,
724727
)),
725728
}
726729
}

src/error.rs

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use crate::{dialog::DialogId, transaction::key::TransactionKey, transport::SipAddr};
2-
use std::env::VarError;
32
use thiserror::Error as ThisError;
4-
use wasm_bindgen::prelude::*;
53

64
#[derive(Debug, ThisError)]
75
pub enum Error {
@@ -21,44 +19,23 @@ pub enum Error {
2119
EndpointError(String),
2220

2321
#[error("Dialog error: {0}: {1}")]
24-
DialogError(String, DialogId),
22+
DialogError(String, DialogId, rsip::StatusCode),
2523

2624
#[error("I/O error: {0}")]
2725
IoError(#[from] std::io::Error),
2826

29-
#[error("Format error: {0}")]
30-
FormatError(#[from] std::fmt::Error),
31-
32-
#[error("Environment variable error: {0}")]
33-
VarError(#[from] VarError),
34-
3527
#[error("Address parse error: {0}")]
3628
AddrParseError(#[from] std::net::AddrParseError),
3729

38-
#[error("TLS error: {0}")]
39-
TlsError(#[from] tokio_rustls::rustls::Error),
40-
4130
#[error("WebSocket error: {0}")]
4231
WebSocketError(#[from] tokio_tungstenite::tungstenite::Error),
4332

44-
#[error("Channel send error: {0}")]
45-
ChannelSendError(String),
46-
47-
#[error("Broadcast receive error: {0}")]
48-
BroadcastRecvError(#[from] tokio::sync::broadcast::error::RecvError),
49-
5033
#[error("Error: {0}")]
5134
Error(String),
5235
}
5336

54-
impl From<Error> for JsValue {
55-
fn from(e: Error) -> Self {
56-
e.to_string().into()
57-
}
58-
}
59-
6037
impl<T> From<tokio::sync::mpsc::error::SendError<T>> for Error {
6138
fn from(e: tokio::sync::mpsc::error::SendError<T>) -> Self {
62-
Error::ChannelSendError(e.to_string())
39+
Error::Error(e.to_string())
6340
}
6441
}

src/transaction/key.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ impl TransactionKey {
8989
role, method, cseq, call_id, from_tag, via.uri.host_with_port
9090
)
9191
}
92-
}?;
92+
}
93+
.map_err(|e| Error::Error(e.to_string()))?;
9394
Ok(TransactionKey(key))
9495
}
9596
}

0 commit comments

Comments
 (0)