mirror of
https://github.com/mikedilger/chorus.git
synced 2026-05-03 06:51:42 +00:00
Removal of errors that are now in pocket
This commit is contained in:
parent
dd9816f86c
commit
577243789e
82
src/error.rs
82
src/error.rs
@ -28,21 +28,12 @@ pub enum ChorusError {
|
|||||||
// Auth required
|
// Auth required
|
||||||
AuthRequired,
|
AuthRequired,
|
||||||
|
|
||||||
// Bad event id
|
|
||||||
BadEventId,
|
|
||||||
|
|
||||||
// Bad hex input
|
|
||||||
BadHexInput,
|
|
||||||
|
|
||||||
// Event is banned
|
// Event is banned
|
||||||
BannedEvent,
|
BannedEvent,
|
||||||
|
|
||||||
// User is banned
|
// User is banned
|
||||||
BannedUser,
|
BannedUser,
|
||||||
|
|
||||||
// Output buffer too small
|
|
||||||
BufferTooSmall,
|
|
||||||
|
|
||||||
// Channel Recv
|
// Channel Recv
|
||||||
ChannelRecv(tokio::sync::broadcast::error::RecvError),
|
ChannelRecv(tokio::sync::broadcast::error::RecvError),
|
||||||
|
|
||||||
@ -55,15 +46,6 @@ pub enum ChorusError {
|
|||||||
// Crypto
|
// Crypto
|
||||||
Crypto(secp256k1::Error),
|
Crypto(secp256k1::Error),
|
||||||
|
|
||||||
// Deleted event
|
|
||||||
Deleted,
|
|
||||||
|
|
||||||
// Duplicate event
|
|
||||||
Duplicate,
|
|
||||||
|
|
||||||
// End of Input
|
|
||||||
EndOfInput,
|
|
||||||
|
|
||||||
// Closing on error(s)
|
// Closing on error(s)
|
||||||
ErrorClose,
|
ErrorClose,
|
||||||
|
|
||||||
@ -79,27 +61,6 @@ pub enum ChorusError {
|
|||||||
// I/O
|
// I/O
|
||||||
Io(std::io::Error),
|
Io(std::io::Error),
|
||||||
|
|
||||||
// JSON Bad (general)
|
|
||||||
JsonBad(&'static str, usize),
|
|
||||||
|
|
||||||
// JSON Bad Character
|
|
||||||
JsonBadCharacter(char, usize, char),
|
|
||||||
|
|
||||||
// JSON Bad Event
|
|
||||||
JsonBadEvent(&'static str, usize),
|
|
||||||
|
|
||||||
// JSON Bad Filter
|
|
||||||
JsonBadFilter(&'static str, usize),
|
|
||||||
|
|
||||||
// JSON Bad String Character
|
|
||||||
JsonBadStringChar(u32),
|
|
||||||
|
|
||||||
// JSON Escape
|
|
||||||
JsonEscape,
|
|
||||||
|
|
||||||
// JSON Escape Surrogate
|
|
||||||
JsonEscapeSurrogate,
|
|
||||||
|
|
||||||
// Missing Table
|
// Missing Table
|
||||||
MissingTable(&'static str),
|
MissingTable(&'static str),
|
||||||
|
|
||||||
@ -121,9 +82,6 @@ pub enum ChorusError {
|
|||||||
// Pocket Types Error
|
// Pocket Types Error
|
||||||
PocketType(pocket_types::Error),
|
PocketType(pocket_types::Error),
|
||||||
|
|
||||||
// Range error
|
|
||||||
RangeError,
|
|
||||||
|
|
||||||
// Restricted
|
// Restricted
|
||||||
Restricted,
|
Restricted,
|
||||||
|
|
||||||
@ -163,42 +121,17 @@ impl std::fmt::Display for ChorusError {
|
|||||||
match self {
|
match self {
|
||||||
ChorusError::AuthFailure(s) => write!(f, "AUTH failure: {s}"),
|
ChorusError::AuthFailure(s) => write!(f, "AUTH failure: {s}"),
|
||||||
ChorusError::AuthRequired => write!(f, "AUTH required"),
|
ChorusError::AuthRequired => write!(f, "AUTH required"),
|
||||||
ChorusError::BadEventId => write!(f, "Bad event id, does not match hash"),
|
|
||||||
ChorusError::BadHexInput => write!(f, "Bad hex input"),
|
|
||||||
ChorusError::BannedEvent => write!(f, "Event is banned"),
|
ChorusError::BannedEvent => write!(f, "Event is banned"),
|
||||||
ChorusError::BannedUser => write!(f, "User is banned"),
|
ChorusError::BannedUser => write!(f, "User is banned"),
|
||||||
ChorusError::BufferTooSmall => write!(f, "Output buffer too small"),
|
|
||||||
ChorusError::ChannelRecv(e) => write!(f, "{e}"),
|
ChorusError::ChannelRecv(e) => write!(f, "{e}"),
|
||||||
ChorusError::ChannelSend(e) => write!(f, "{e}"),
|
ChorusError::ChannelSend(e) => write!(f, "{e}"),
|
||||||
ChorusError::Config(e) => write!(f, "{e}"),
|
ChorusError::Config(e) => write!(f, "{e}"),
|
||||||
ChorusError::Crypto(e) => write!(f, "{e}"),
|
ChorusError::Crypto(e) => write!(f, "{e}"),
|
||||||
ChorusError::Deleted => write!(f, "Event was previously deleted"),
|
|
||||||
ChorusError::Duplicate => write!(f, "Duplicate event"),
|
|
||||||
ChorusError::EndOfInput => write!(f, "End of input"),
|
|
||||||
ChorusError::ErrorClose => write!(f, "Closing due to error(s)"),
|
ChorusError::ErrorClose => write!(f, "Closing due to error(s)"),
|
||||||
ChorusError::EventIsInvalid(s) => write!(f, "Event is invalid: {s}"),
|
ChorusError::EventIsInvalid(s) => write!(f, "Event is invalid: {s}"),
|
||||||
ChorusError::Http(e) => write!(f, "{e}"),
|
ChorusError::Http(e) => write!(f, "{e}"),
|
||||||
ChorusError::Hyper(e) => write!(f, "{e}"),
|
ChorusError::Hyper(e) => write!(f, "{e}"),
|
||||||
ChorusError::Io(e) => write!(f, "{e}"),
|
ChorusError::Io(e) => write!(f, "{e}"),
|
||||||
ChorusError::JsonBad(err, pos) => write!(f, "JSON bad: {err} at position {pos}"),
|
|
||||||
ChorusError::JsonBadCharacter(c, pos, ec) => write!(
|
|
||||||
f,
|
|
||||||
"JSON bad character: {c} at position {pos}, {ec} was expected"
|
|
||||||
),
|
|
||||||
ChorusError::JsonBadEvent(err, pos) => {
|
|
||||||
write!(f, "JSON bad event: {err} at position {pos}")
|
|
||||||
}
|
|
||||||
ChorusError::JsonBadFilter(err, pos) => {
|
|
||||||
write!(f, "JSON bad filter: {err} at position {pos}")
|
|
||||||
}
|
|
||||||
ChorusError::JsonBadStringChar(ch) => {
|
|
||||||
write!(f, "JSON string bad character: codepoint {ch}")
|
|
||||||
}
|
|
||||||
ChorusError::JsonEscape => write!(f, "JSON string escape error"),
|
|
||||||
ChorusError::JsonEscapeSurrogate => write!(
|
|
||||||
f,
|
|
||||||
"JSON string escape surrogate (ancient style) is not supported"
|
|
||||||
),
|
|
||||||
ChorusError::MissingTable(t) => write!(f, "Missing table: {t}"),
|
ChorusError::MissingTable(t) => write!(f, "Missing table: {t}"),
|
||||||
ChorusError::NoPrivateKey => write!(f, "Private Key Not Found"),
|
ChorusError::NoPrivateKey => write!(f, "Private Key Not Found"),
|
||||||
ChorusError::NoSuchSubscription => write!(f, "No such subscription"),
|
ChorusError::NoSuchSubscription => write!(f, "No such subscription"),
|
||||||
@ -206,7 +139,6 @@ impl std::fmt::Display for ChorusError {
|
|||||||
ChorusError::PocketDbHeed(e) => write!(f, "{e}"),
|
ChorusError::PocketDbHeed(e) => write!(f, "{e}"),
|
||||||
ChorusError::PocketType(e) => write!(f, "{e}"),
|
ChorusError::PocketType(e) => write!(f, "{e}"),
|
||||||
ChorusError::ProtectedEvent => write!(f, "Protected event"),
|
ChorusError::ProtectedEvent => write!(f, "Protected event"),
|
||||||
ChorusError::RangeError => write!(f, "Range error"),
|
|
||||||
ChorusError::Restricted => write!(f, "Restricted"),
|
ChorusError::Restricted => write!(f, "Restricted"),
|
||||||
ChorusError::Rustls(e) => write!(f, "{e}"),
|
ChorusError::Rustls(e) => write!(f, "{e}"),
|
||||||
ChorusError::TimedOut => write!(f, "Timed out"),
|
ChorusError::TimedOut => write!(f, "Timed out"),
|
||||||
@ -251,30 +183,17 @@ impl ChorusError {
|
|||||||
match self {
|
match self {
|
||||||
ChorusError::AuthFailure(_) => 0.25,
|
ChorusError::AuthFailure(_) => 0.25,
|
||||||
ChorusError::AuthRequired => 0.0,
|
ChorusError::AuthRequired => 0.0,
|
||||||
ChorusError::BadEventId => 0.1,
|
|
||||||
ChorusError::BadHexInput => 0.4,
|
|
||||||
ChorusError::BannedEvent => 0.1,
|
ChorusError::BannedEvent => 0.1,
|
||||||
ChorusError::BannedUser => 0.2,
|
ChorusError::BannedUser => 0.2,
|
||||||
ChorusError::BufferTooSmall => 0.0,
|
|
||||||
ChorusError::ChannelRecv(_) => 0.0,
|
ChorusError::ChannelRecv(_) => 0.0,
|
||||||
ChorusError::ChannelSend(_) => 0.0,
|
ChorusError::ChannelSend(_) => 0.0,
|
||||||
ChorusError::Config(_) => 0.0,
|
ChorusError::Config(_) => 0.0,
|
||||||
ChorusError::Crypto(_) => 0.1,
|
ChorusError::Crypto(_) => 0.1,
|
||||||
ChorusError::Deleted => 0.1,
|
|
||||||
ChorusError::Duplicate => 0.01,
|
|
||||||
ChorusError::EndOfInput => 0.4,
|
|
||||||
ChorusError::ErrorClose => 1.0,
|
ChorusError::ErrorClose => 1.0,
|
||||||
ChorusError::EventIsInvalid(_) => 0.2,
|
ChorusError::EventIsInvalid(_) => 0.2,
|
||||||
ChorusError::Http(_) => 0.0,
|
ChorusError::Http(_) => 0.0,
|
||||||
ChorusError::Hyper(_) => 0.0,
|
ChorusError::Hyper(_) => 0.0,
|
||||||
ChorusError::Io(_) => 0.0,
|
ChorusError::Io(_) => 0.0,
|
||||||
ChorusError::JsonBad(_, _) => 0.2,
|
|
||||||
ChorusError::JsonBadCharacter(_, _, _) => 0.2,
|
|
||||||
ChorusError::JsonBadEvent(_, _) => 0.2,
|
|
||||||
ChorusError::JsonBadFilter(_, _) => 0.2,
|
|
||||||
ChorusError::JsonBadStringChar(_) => 0.2,
|
|
||||||
ChorusError::JsonEscape => 0.2,
|
|
||||||
ChorusError::JsonEscapeSurrogate => 0.05,
|
|
||||||
ChorusError::MissingTable(_) => 0.0,
|
ChorusError::MissingTable(_) => 0.0,
|
||||||
ChorusError::NoPrivateKey => 0.0,
|
ChorusError::NoPrivateKey => 0.0,
|
||||||
ChorusError::NoSuchSubscription => 0.05,
|
ChorusError::NoSuchSubscription => 0.05,
|
||||||
@ -282,7 +201,6 @@ impl ChorusError {
|
|||||||
ChorusError::PocketDbHeed(_) => 0.0,
|
ChorusError::PocketDbHeed(_) => 0.0,
|
||||||
ChorusError::PocketType(_) => 0.0,
|
ChorusError::PocketType(_) => 0.0,
|
||||||
ChorusError::ProtectedEvent => 0.35,
|
ChorusError::ProtectedEvent => 0.35,
|
||||||
ChorusError::RangeError => 0.0,
|
|
||||||
ChorusError::Restricted => 0.1,
|
ChorusError::Restricted => 0.1,
|
||||||
ChorusError::Rustls(_) => 0.0,
|
ChorusError::Rustls(_) => 0.0,
|
||||||
ChorusError::TimedOut => 0.1,
|
ChorusError::TimedOut => 0.1,
|
||||||
|
|||||||
21
src/nostr.rs
21
src/nostr.rs
@ -211,15 +211,6 @@ impl WebSocketService {
|
|||||||
NostrReplyPrefix::AuthRequired,
|
NostrReplyPrefix::AuthRequired,
|
||||||
PERSONAL_MSG.to_owned(),
|
PERSONAL_MSG.to_owned(),
|
||||||
),
|
),
|
||||||
ChorusError::Duplicate => {
|
|
||||||
NostrReply::Ok(id, true, NostrReplyPrefix::Duplicate, "".to_string())
|
|
||||||
}
|
|
||||||
ChorusError::Deleted => NostrReply::Ok(
|
|
||||||
id,
|
|
||||||
false,
|
|
||||||
NostrReplyPrefix::Blocked,
|
|
||||||
"That event is deleted".to_string(),
|
|
||||||
),
|
|
||||||
ChorusError::EventIsInvalid(ref why) => {
|
ChorusError::EventIsInvalid(ref why) => {
|
||||||
log::error!(target: "Client", "{}: {}", self.peer, e);
|
log::error!(target: "Client", "{}: {}", self.peer, e);
|
||||||
NostrReply::Ok(id, false, NostrReplyPrefix::Invalid, why.to_string())
|
NostrReply::Ok(id, false, NostrReplyPrefix::Invalid, why.to_string())
|
||||||
@ -245,6 +236,18 @@ impl WebSocketService {
|
|||||||
NostrReplyPrefix::Blocked,
|
NostrReplyPrefix::Blocked,
|
||||||
"Author has been banned".to_string(),
|
"Author has been banned".to_string(),
|
||||||
),
|
),
|
||||||
|
ChorusError::PocketDb(ref pe) => match pe.inner {
|
||||||
|
pocket_db::InnerError::Deleted => NostrReply::Ok(
|
||||||
|
id,
|
||||||
|
false,
|
||||||
|
NostrReplyPrefix::Blocked,
|
||||||
|
"That event is deleted".to_string(),
|
||||||
|
),
|
||||||
|
pocket_db::InnerError::Duplicate => {
|
||||||
|
NostrReply::Ok(id, true, NostrReplyPrefix::Duplicate, "".to_string())
|
||||||
|
}
|
||||||
|
_ => NostrReply::Ok(id, false, NostrReplyPrefix::Error, format!("{}", e)),
|
||||||
|
},
|
||||||
_ => NostrReply::Ok(id, false, NostrReplyPrefix::Error, format!("{}", e)),
|
_ => NostrReply::Ok(id, false, NostrReplyPrefix::Error, format!("{}", e)),
|
||||||
};
|
};
|
||||||
self.websocket.send(Message::text(reply.as_json())).await?;
|
self.websocket.send(Message::text(reply.as_json())).await?;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user