Skip to content

Commit

Permalink
Merge pull request #82 from nemosupremo/feat/status-code
Browse files Browse the repository at this point in the history
Error: Add a status_code method on the Error struct to query the RTSP status code, if any
  • Loading branch information
scottlamb authored Jan 3, 2024
2 parents 0862ad5 + f5c87df commit 77265a4
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ use thiserror::Error;
#[derive(Clone)]
pub struct Error(pub(crate) Arc<ErrorInt>);

impl Error {
/// Returns the status code, if the error was generated from a response.
pub fn status_code(&self) -> Option<u16> {
match self.0.as_ref() {
ErrorInt::RtspResponseError { status, .. } => Some((*status).into()),
_ => None,
}
}
}

impl Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
Expand Down

0 comments on commit 77265a4

Please sign in to comment.