li7y/src/middleware/error_handlers.rs
2024-07-19 00:06:11 +02:00

20 lines
579 B
Rust

// SPDX-FileCopyrightText: 2024 Simon Bruder <simon@sbruder.de>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use actix_web::middleware::ErrorHandlerResponse;
use actix_web::{dev::ServiceResponse, error, HttpResponse};
pub fn redirect_to_login<B>(
res: ServiceResponse<B>,
) -> Result<ErrorHandlerResponse<B>, error::Error> {
Ok(ErrorHandlerResponse::Response(
res.into_response(
HttpResponse::SeeOther()
.insert_header(("Location", "/login"))
.finish()
.map_into_right_body(),
),
))
}