walker_common/retrieve/
error.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use crate::{source::Source, utils::url::Urlify};
use std::fmt::Debug;
use url::Url;

/// An error from a retrieval visitor.
#[derive(Clone, Debug, thiserror::Error)]
pub enum RetrievalError<D, S>
where
    D: Urlify,
    S: Source,
{
    /// Failed to fetch the discovered document from the source.
    #[error("source error: {err}")]
    Source { err: S::Error, discovered: D },
}

impl<D, S> RetrievalError<D, S>
where
    D: Urlify,
    S: Source,
{
    pub fn discovered(&self) -> &D {
        match self {
            Self::Source { discovered, .. } => discovered,
        }
    }
}

impl<S, D> Urlify for RetrievalError<D, S>
where
    D: Urlify,
    S: Source,
{
    fn url(&self) -> &Url {
        match self {
            Self::Source { discovered, .. } => discovered.url(),
        }
    }
}