distinguish opted out channels and users
This commit is contained in:
parent
b160f8452e
commit
c44c9d8776
|
@ -127,12 +127,12 @@ impl App {
|
|||
|
||||
pub fn check_opted_out(&self, channel_id: &str, user_id: Option<&str>) -> Result<()> {
|
||||
if self.config.opt_out.contains_key(channel_id) {
|
||||
return Err(Error::OptedOut);
|
||||
return Err(Error::ChannelOptedOut);
|
||||
}
|
||||
|
||||
if let Some(user_id) = user_id {
|
||||
if self.config.opt_out.contains_key(user_id) {
|
||||
return Err(Error::OptedOut);
|
||||
return Err(Error::UserOptedOut);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
17
src/error.rs
17
src/error.rs
|
@ -20,8 +20,10 @@ pub enum Error {
|
|||
Internal,
|
||||
#[error("Database error")]
|
||||
Clickhouse(#[from] clickhouse::error::Error),
|
||||
#[error("User or channel has opted out")]
|
||||
OptedOut,
|
||||
#[error("The requested channel has opted out of being logged")]
|
||||
ChannelOptedOut,
|
||||
#[error("The requested user has opted out of being logged")]
|
||||
UserOptedOut,
|
||||
#[error("Not found")]
|
||||
NotFound,
|
||||
}
|
||||
|
@ -35,7 +37,7 @@ impl IntoResponse for Error {
|
|||
StatusCode::INTERNAL_SERVER_ERROR
|
||||
}
|
||||
Error::ParseInt(_) | Error::InvalidParam(_) => StatusCode::BAD_REQUEST,
|
||||
Error::OptedOut => StatusCode::FORBIDDEN,
|
||||
Error::ChannelOptedOut | Error::UserOptedOut => StatusCode::FORBIDDEN,
|
||||
Error::NotFound => StatusCode::NOT_FOUND,
|
||||
};
|
||||
|
||||
|
@ -82,7 +84,14 @@ impl OperationOutput for Error {
|
|||
(
|
||||
Some(403),
|
||||
aide::openapi::Response {
|
||||
description: Error::OptedOut.to_string(),
|
||||
description: Error::ChannelOptedOut.to_string(),
|
||||
..res.clone()
|
||||
},
|
||||
),
|
||||
(
|
||||
Some(403),
|
||||
aide::openapi::Response {
|
||||
description: Error::UserOptedOut.to_string(),
|
||||
..res.clone()
|
||||
},
|
||||
),
|
||||
|
|
Loading…
Reference in New Issue