replace expect with ErrorUnauthorized (#3915)

Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
This commit is contained in:
Lukas Trombach 2023-08-30 11:08:44 +12:00 committed by GitHub
parent b2aee565f3
commit c93bde9799
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -92,9 +92,9 @@ async fn upload(
context: web::Data<LemmyContext>,
) -> Result<HttpResponse, Error> {
// TODO: check rate limit here
let jwt = req
.cookie("jwt")
.expect("No auth header for picture upload");
let jwt = req.cookie("jwt").ok_or(error::ErrorUnauthorized(
"No auth header for picture upload",
))?;
if Claims::decode(jwt.value(), &context.secret().jwt_secret).is_err() {
return Ok(HttpResponse::Unauthorized().finish());
@ -133,9 +133,9 @@ async fn full_res(
.await
.map_err(error::ErrorBadRequest)?;
if local_site.private_instance {
let jwt = req
.cookie("jwt")
.expect("No auth header for picture access");
let jwt = req.cookie("jwt").ok_or(error::ErrorUnauthorized(
"No auth header for picture access",
))?;
if local_user_view_from_jwt(jwt.value(), &context)
.await
.is_err()