nostr_browser_signer_proxy/
error.rs

1// Copyright (c) 2022-2023 Yuki Kishimoto
2// Copyright (c) 2023-2025 Rust Nostr Developers
3// Distributed under the MIT software license
4
5//! Error
6
7use std::{fmt, io};
8
9use hyper::http;
10use nostr::event;
11use tokio::sync::oneshot::error::RecvError;
12
13/// Error
14#[derive(Debug)]
15pub enum Error {
16    /// I/O error
17    Io(io::Error),
18    /// HTTP error
19    Http(http::Error),
20    /// Json error
21    Json(serde_json::Error),
22    /// Event error
23    Event(event::Error),
24    /// Oneshot channel receive error
25    OneShotRecv(RecvError),
26    /// Generic error
27    Generic(String),
28    /// Timeout
29    Timeout,
30    /// The server is shutdown
31    Shutdown,
32}
33
34impl std::error::Error for Error {}
35
36impl fmt::Display for Error {
37    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38        match self {
39            Self::Io(e) => write!(f, "{e}"),
40            Self::Http(e) => write!(f, "{e}"),
41            Self::Json(e) => write!(f, "{e}"),
42            Self::Event(e) => write!(f, "{e}"),
43            Self::OneShotRecv(e) => write!(f, "{e}"),
44            Self::Generic(e) => write!(f, "{e}"),
45            Self::Timeout => write!(f, "timeout"),
46            Self::Shutdown => write!(f, "server is shutdown"),
47        }
48    }
49}
50
51impl From<io::Error> for Error {
52    fn from(e: io::Error) -> Self {
53        Self::Io(e)
54    }
55}
56
57impl From<http::Error> for Error {
58    fn from(e: http::Error) -> Self {
59        Self::Http(e)
60    }
61}
62
63impl From<serde_json::Error> for Error {
64    fn from(e: serde_json::Error) -> Self {
65        Self::Json(e)
66    }
67}
68
69impl From<event::Error> for Error {
70    fn from(e: event::Error) -> Self {
71        Self::Event(e)
72    }
73}
74
75impl From<RecvError> for Error {
76    fn from(e: RecvError) -> Self {
77        Self::OneShotRecv(e)
78    }
79}