|
44 | 44 | use crate::templates::SplitTemplate; |
45 | 45 | use crate::webserver::http::RequestContext; |
46 | 46 | use crate::webserver::response_writer::{AsyncResponseWriter, ResponseWriter}; |
| 47 | +use crate::webserver::ErrorWithStatus; |
47 | 48 | use crate::AppState; |
48 | 49 | use actix_web::cookie::time::format_description::well_known::Rfc3339; |
49 | 50 | use actix_web::cookie::time::OffsetDateTime; |
50 | | -use actix_web::http::header::ContentType; |
51 | 51 | use actix_web::http::{header, StatusCode}; |
52 | 52 | use actix_web::{HttpResponse, HttpResponseBuilder}; |
53 | 53 | use anyhow::{bail, format_err, Context as AnyhowContext}; |
@@ -323,15 +323,9 @@ impl HeaderContext { |
323 | 323 | Redirecting to the login page...", |
324 | 324 | ) |
325 | 325 | } else { |
326 | | - let mut resp_builder = actix_web::HttpResponse::build(StatusCode::UNAUTHORIZED); |
327 | | - resp_builder.content_type(ContentType::plaintext()); |
328 | | - resp_builder.insert_header(( |
329 | | - header::WWW_AUTHENTICATE, |
330 | | - header::HeaderValue::from_static( |
331 | | - "Basic realm=\"Authentication required\", charset=\"UTF-8\"", |
332 | | - ), |
333 | | - )); |
334 | | - resp_builder.body("Sorry, but you are not authorized to access this page.") |
| 326 | + anyhow::bail!(ErrorWithStatus { |
| 327 | + status: StatusCode::UNAUTHORIZED |
| 328 | + }) |
335 | 329 | }; |
336 | 330 | self.has_status = true; |
337 | 331 | Ok(PageContext::Close(http_response)) |
|
0 commit comments