1
0
mirror of https://github.com/scsibug/nostr-rs-relay.git synced 2025-03-21 19:22:26 -04:00

55 lines
1.3 KiB
Rust
Raw Normal View History

2021-12-11 21:43:41 -06:00
//! Error handling
use std::result;
use thiserror::Error;
use tungstenite::error::Error as WsError;
2021-12-11 21:43:41 -06:00
/// Simple `Result` type for errors in this module
pub type Result<T, E = Error> = result::Result<T, E>;
2021-12-11 21:43:41 -06:00
/// Custom error type for Nostr
#[derive(Error, Debug)]
pub enum Error {
#[error("Protocol parse error")]
ProtoParseError,
#[error("Connection error")]
ConnError,
#[error("Client write error")]
ConnWriteError,
#[error("EVENT parse failed")]
EventParseFailed,
#[error("ClOSE message parse failed")]
CloseParseFailed,
#[error("Event validation failed")]
EventInvalid,
// this should be used if the JSON is invalid
#[error("JSON parsing failed")]
JsonParseFailed(serde_json::Error),
#[error("WebSocket proto error")]
WebsocketError(WsError),
#[error("Command unknown")]
CommandUnknownError,
#[error("SQL error")]
SqlError(rusqlite::Error),
}
impl From<rusqlite::Error> for Error {
2021-12-11 21:43:41 -06:00
/// Wrap SQL error
fn from(r: rusqlite::Error) -> Self {
Error::SqlError(r)
}
}
impl From<serde_json::Error> for Error {
2021-12-11 21:43:41 -06:00
/// Wrap JSON error
fn from(r: serde_json::Error) -> Self {
Error::JsonParseFailed(r)
}
}
impl From<WsError> for Error {
2021-12-11 21:43:41 -06:00
/// Wrap Websocket error
fn from(r: WsError) -> Self {
Error::WebsocketError(r)
}
}