-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Error if send or receive session expired
- Loading branch information
Showing
6 changed files
with
137 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use core::fmt; | ||
use std::error; | ||
|
||
use crate::v2::OhttpEncapsulationError; | ||
|
||
#[derive(Debug)] | ||
pub struct SessionError(InternalSessionError); | ||
|
||
#[derive(Debug)] | ||
pub(crate) enum InternalSessionError { | ||
/// The session has expired | ||
Expired(std::time::SystemTime), | ||
/// OHTTP Encapsulation failed | ||
OhttpEncapsulationError(OhttpEncapsulationError), | ||
} | ||
|
||
impl fmt::Display for SessionError { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
match &self.0 { | ||
InternalSessionError::Expired(expiry) => write!(f, "Session expired at {:?}", expiry), | ||
InternalSessionError::OhttpEncapsulationError(e) => | ||
write!(f, "OHTTP Encapsulation Error: {}", e), | ||
} | ||
} | ||
} | ||
|
||
impl error::Error for SessionError { | ||
fn source(&self) -> Option<&(dyn error::Error + 'static)> { | ||
match &self.0 { | ||
InternalSessionError::Expired(_) => None, | ||
InternalSessionError::OhttpEncapsulationError(e) => Some(e), | ||
} | ||
} | ||
} | ||
|
||
impl From<InternalSessionError> for SessionError { | ||
fn from(e: InternalSessionError) -> Self { SessionError(e) } | ||
} | ||
|
||
impl From<OhttpEncapsulationError> for SessionError { | ||
fn from(e: OhttpEncapsulationError) -> Self { | ||
SessionError(InternalSessionError::OhttpEncapsulationError(e)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters