Keep the podcast API's 401 path out of a large Result

Clippy flagged the helper that returned the 401 response as its error
variant (result_large_err); it now returns the account id as an Option.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
sanapachandClaude Opus 5.5 committed 2026-11-20 15:12:38 +02:00
1 parent bf6981948a
commit 047fc9e887
1 file changed
+19 -25
+19 -25
View File
@@ -93,16 +93,15 @@ fn api_response<T: Serialize>(result: api::ApiResult<T>) -> cot::Result<cot::res
}
}
/// The signed-in account, or the 401 response.
async fn signed_in(
auth_ctx: &auth::AuthContext,
session: &Session,
db: &Database,
) -> Result<i64, cot::response::Response> {
match auth::get_request_user(auth_ctx, session, db).await {
Some(user) => Ok(user.id),
None => Err(json_error(StatusCode::UNAUTHORIZED, "not authenticated")),
}
/// The signed-in account (session or bearer token).
async fn signed_in(auth_ctx: &auth::AuthContext, session: &Session, db: &Database) -> Option<i64> {
auth::get_request_user(auth_ctx, session, db)
.await
.map(|user| user.id)
}
fn unauthorized() -> cot::response::Response {
json_error(StatusCode::UNAUTHORIZED, "not authenticated")
}
/// Largest JSON body accepted (a playback request carries one episode reference).
@@ -413,9 +412,8 @@ async fn list_handler(
db: Database,
query: UrlQuery<ListQuery>,
) -> cot::Result<cot::response::Response> {
let user_id = match signed_in(&auth_ctx, &session, &db).await {
Ok(user_id) => user_id,
Err(response) => return Ok(response),
let Some(user_id) = signed_in(&auth_ctx, &session, &db).await else {
return Ok(unauthorized());
};
let all = matches!(query.0.all.as_deref(), Some("1" | "true"));
let store = state.store().await?;
@@ -429,9 +427,8 @@ async fn subscribe_url_handler(
db: Database,
request: cot::request::Request,
) -> cot::Result<cot::response::Response> {
let user_id = match signed_in(&auth_ctx, &session, &db).await {
Ok(user_id) => user_id,
Err(response) => return Ok(response),
let Some(user_id) = signed_in(&auth_ctx, &session, &db).await else {
return Ok(unauthorized());
};
let body = match json_body(request).await {
Ok(body) => body,
@@ -458,9 +455,8 @@ async fn podcast_handler(
db: Database,
path: Path<PodcastPath>,
) -> cot::Result<cot::response::Response> {
let user_id = match signed_in(&auth_ctx, &session, &db).await {
Ok(user_id) => user_id,
Err(response) => return Ok(response),
let Some(user_id) = signed_in(&auth_ctx, &session, &db).await else {
return Ok(unauthorized());
};
let podcast_id = match api::parse_podcast_id(&path.0.podcast_id) {
Ok(id) => id,
@@ -488,9 +484,8 @@ async fn episodes_handler(
path: Path<PodcastPath>,
query: UrlQuery<EpisodeListParams>,
) -> cot::Result<cot::response::Response> {
let user_id = match signed_in(&auth_ctx, &session, &db).await {
Ok(user_id) => user_id,
Err(response) => return Ok(response),
let Some(user_id) = signed_in(&auth_ctx, &session, &db).await else {
return Ok(unauthorized());
};
let podcast_id = match api::parse_podcast_id(&path.0.podcast_id) {
Ok(id) => id,
@@ -517,9 +512,8 @@ async fn episode_handler(
path: Path<EpisodePath>,
request: cot::request::Request,
) -> cot::Result<cot::response::Response> {
let user_id = match signed_in(&auth_ctx, &session, &db).await {
Ok(user_id) => user_id,
Err(response) => return Ok(response),
let Some(user_id) = signed_in(&auth_ctx, &session, &db).await else {
return Ok(unauthorized());
};
let episode_id = match api::parse_episode_id(&path.0.episode_id) {
Ok(id) => id,