better_fetch/
miette_diagnostic.rs1use http::Method;
4use miette::Diagnostic;
5use thiserror::Error;
6use url::Url;
7
8use crate::error::Error;
9
10#[derive(Debug, Error, Diagnostic)]
12#[error("{inner}")]
13pub struct DiagnosticError {
14 #[source]
15 inner: Error,
16 #[help]
17 method: Option<String>,
18 #[help]
19 url: Option<String>,
20}
21
22impl DiagnosticError {
23 pub fn new(error: Error, method: Option<&Method>, url: Option<&Url>) -> Self {
25 Self {
26 inner: error,
27 method: method.map(|m| m.to_string()),
28 url: url.map(|u| u.to_string()),
29 }
30 }
31}
32
33impl From<Error> for DiagnosticError {
34 fn from(inner: Error) -> Self {
35 Self {
36 inner,
37 method: None,
38 url: None,
39 }
40 }
41}