Skip to main content

leyline/core/error/
marker.rs

1use std::fmt;
2
3use super::{Error, Kind};
4
5#[derive(Debug)]
6pub(crate) struct ShutDown;
7
8impl fmt::Display for ShutDown {
9    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10        f.write_str(SHUT_DOWN_MESSAGE)
11    }
12}
13
14impl std::error::Error for ShutDown {}
15
16#[derive(Debug)]
17pub(crate) struct NotProcessed;
18
19impl fmt::Display for NotProcessed {
20    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21        f.write_str("the server did not process the request")
22    }
23}
24
25impl std::error::Error for NotProcessed {}
26
27const SHUT_DOWN_MESSAGE: &str = "session shut down";
28
29impl Error {
30    pub(crate) fn shut_down() -> Error {
31        Error::new(Kind::Request)
32            .with_message(SHUT_DOWN_MESSAGE)
33            .with_source(ShutDown)
34    }
35
36    pub fn is_shut_down(&self) -> bool {
37        self.source_as::<ShutDown>().is_some()
38    }
39
40    pub(crate) fn not_processed(&self) -> bool {
41        self.source_as::<NotProcessed>().is_some()
42    }
43}