mirror of
https://github.com/scsibug/nostr-rs-relay.git
synced 2024-11-22 09:09:07 -05: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,
|
Blocked,
|
||||||
RateLimited,
|
RateLimited,
|
||||||
Error,
|
Error,
|
||||||
|
Restricted,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct EventResult {
|
pub struct EventResult {
|
||||||
|
@ -24,7 +25,7 @@ impl EventResultStatus {
|
||||||
pub fn to_bool(&self) -> bool {
|
pub fn to_bool(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Self::Duplicate | Self::Saved => true,
|
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::Blocked => "blocked",
|
||||||
Self::RateLimited => "rate-limited",
|
Self::RateLimited => "rate-limited",
|
||||||
Self::Error => "error",
|
Self::Error => "error",
|
||||||
|
Self::Restricted => "restricted",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,6 +83,11 @@ impl Notice {
|
||||||
Notice::prefixed(id, msg, EventResultStatus::Error)
|
Notice::prefixed(id, msg, EventResultStatus::Error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn restricted(id: String, msg: &str) -> Notice {
|
||||||
|
Notice::prefixed(id, msg, EventResultStatus::Restricted)
|
||||||
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn saved(id: String) -> Notice {
|
pub fn saved(id: String) -> Notice {
|
||||||
Notice::EventResult(EventResult {
|
Notice::EventResult(EventResult {
|
||||||
|
|
|
@ -1317,7 +1317,7 @@ async fn nostr_server(
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
info!("authentication error: {} (cid: {})", e, cid);
|
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