mirror of
https://github.com/scsibug/nostr-rs-relay.git
synced 2024-05-19 21:24:08 -04:00
improvement(NIP-42): use 'restricted:' prefix for auth error msgs
This commit is contained in:
parent
a34516628b
commit
2f10271903
|
@ -5,6 +5,7 @@ pub enum EventResultStatus {
|
|||
Blocked,
|
||||
RateLimited,
|
||||
Error,
|
||||
Restricted,
|
||||
}
|
||||
|
||||
pub struct EventResult {
|
||||
|
@ -24,7 +25,7 @@ impl EventResultStatus {
|
|||
pub fn to_bool(&self) -> bool {
|
||||
match self {
|
||||
Self::Duplicate | Self::Saved => true,
|
||||
Self::Invalid | Self::Blocked | Self::RateLimited | Self::Error => false,
|
||||
Self::Invalid | Self::Blocked | Self::RateLimited | Self::Error | Self::Restricted => false,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,6 +38,7 @@ impl EventResultStatus {
|
|||
Self::Blocked => "blocked",
|
||||
Self::RateLimited => "rate-limited",
|
||||
Self::Error => "error",
|
||||
Self::Restricted => "restricted",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -81,6 +83,11 @@ impl Notice {
|
|||
Notice::prefixed(id, msg, EventResultStatus::Error)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn restricted(id: String, msg: &str) -> Notice {
|
||||
Notice::prefixed(id, msg, EventResultStatus::Restricted)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn saved(id: String) -> Notice {
|
||||
Notice::EventResult(EventResult {
|
||||
|
|
|
@ -1317,7 +1317,7 @@ async fn nostr_server(
|
|||
},
|
||||
Err(e) => {
|
||||
info!("authentication error: {} (cid: {})", e, cid);
|
||||
ws_stream.send(make_notice_message(&Notice::message(format!("Authentication error: {e}")))).await.ok();
|
||||
ws_stream.send(make_notice_message(&Notice::restricted(event.id, format!("authentication error: {e}").as_str()))).await.ok();
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user