fix(gateway): avoid expect on checked forum session
This commit is contained in:
parent
c18ccadf99
commit
85a2d25844
1 changed files with 10 additions and 13 deletions
|
|
@ -140,19 +140,14 @@ pub async fn handle(
|
|||
Some(invalid("forum offset is too large"))
|
||||
} else if operation.is_none() || operation == Some(ForumOperation::Unspecified) {
|
||||
Some(invalid("unsupported forum operation"))
|
||||
} else if channel.is_none() {
|
||||
Some((proto::ErrorCode::ChannelNotFound, "forum not found"))
|
||||
} else if session.is_none() {
|
||||
Some((proto::ErrorCode::AuthFailed, "session not found"))
|
||||
} else {
|
||||
authorize(
|
||||
state,
|
||||
session.as_ref().expect("checked session"),
|
||||
channel.as_ref().expect("checked forum"),
|
||||
posting,
|
||||
)
|
||||
.await?
|
||||
.err()
|
||||
match (&session, &channel) {
|
||||
(_, None) => Some((proto::ErrorCode::ChannelNotFound, "forum not found")),
|
||||
(None, _) => Some((proto::ErrorCode::AuthFailed, "session not found")),
|
||||
(Some(session), Some(channel)) => {
|
||||
authorize(state, session, channel, posting).await?.err()
|
||||
}
|
||||
}
|
||||
};
|
||||
if let Some((code, error)) = rejection {
|
||||
result.error_code = code as u32;
|
||||
|
|
@ -160,7 +155,9 @@ pub async fn handle(
|
|||
drop(guard);
|
||||
return send(stream, seq, result).await;
|
||||
}
|
||||
let session = session.expect("checked session");
|
||||
let Some(session) = session else {
|
||||
return Ok(());
|
||||
};
|
||||
if !state.rate_limiter.try_consume(sid) {
|
||||
result.error_code = proto::ErrorCode::RateLimited as u32;
|
||||
result.error = "forum requests are too frequent".into();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue