li7y/src/middleware/error_handlers.rs

20 lines
579 B
Rust
Raw Normal View History

2024-07-13 13:41:23 +02:00
// 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(),
),
))
}