Return Unauthorized if user extension missing
Instead of returning an internal error if the user has not been added to
the extensions, return an unauthorized response.
This particular error will occur if a custom auth has been used, and
hasn't provided this type of mapping.
@@ -105,13 +105,10 @@ pub(crate) fn get_authorized_user(
) -> Result<User, ErrorHttpResponse> {
match request.extensions().get::<User>().cloned() {
Some(user) => Ok(user),
- None => {
- error!("Biome routes have not been wrapped in an authorization middleware");
- Err(Box::new(
- HttpResponse::InternalServerError()
- .json(ErrorResponse::internal_error())
+ None => Err(Box::new(
+ HttpResponse::Unauthorized()
+ .json(ErrorResponse::unauthorized())
.into_future(),
- ))
- }
+ )),
}
}
