railway_core/
error.rs

1use std::error::Error as StdError;
2use std::fmt::{Display, Formatter};
3
4/// An error in the API.
5#[derive(Debug)]
6pub enum Error<R, P> {
7    /// Error requesting data using the [`Requester`](crate::Requester).
8    Request(R),
9    /// Any [`Provider`](crate::Provider)-specific error, e.g. failing to parse the response from the API.
10    Provider(P), // TODO: Journey not found, ...
11    /// Provider doesn't have implementation for this specific feature
12    NotImplemented,
13}
14
15impl<R: Display, P: Display> Display for Error<R, P> {
16    fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
17        match self {
18            Self::Request(e) => write!(f, "error requesting data: {}", e),
19            Self::Provider(e) => write!(f, "provider specific error: {}", e),
20            Self::NotImplemented => write!(f, "not implemented by this provider"),
21        }
22    }
23}
24
25impl<R: StdError, P: StdError> StdError for Error<R, P> {}