From fa0c2865366b1bb65a2977c4b9608c9a92fc5889 Mon Sep 17 00:00:00 2001 From: boastful-squirrel Date: Wed, 1 May 2019 18:23:29 +0200 Subject: Use HTTP StatusCode for error title --- src/auth.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/auth.rs') diff --git a/src/auth.rs b/src/auth.rs index 889498e..dbb501d 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -1,4 +1,4 @@ -use actix_web::http::header; +use actix_web::http::{header, StatusCode}; use actix_web::middleware::{Middleware, Response}; use actix_web::{HttpRequest, HttpResponse, Result}; use sha2::{Digest, Sha256, Sha512}; @@ -98,7 +98,7 @@ impl Middleware for Auth { let auth_err = ContextualError::HTTPAuthenticationError(Box::new(err)); return Ok(Response::Done( HttpResponse::BadRequest() - .body(build_unauthorized_response(&req, auth_err, true)), + .body(build_unauthorized_response(&req, auth_err, true, StatusCode::BAD_REQUEST)), )); } }; @@ -108,6 +108,7 @@ impl Middleware for Auth { &req, ContextualError::InvalidHTTPCredentials, true, + StatusCode::UNAUTHORIZED, ), ))); } @@ -121,6 +122,7 @@ impl Middleware for Auth { &req, ContextualError::InvalidHTTPCredentials, false, + StatusCode::UNAUTHORIZED, )); return Ok(Response::Done(new_resp)); } @@ -136,6 +138,7 @@ fn build_unauthorized_response( req: &HttpRequest, error: ContextualError, log_error_chain: bool, + error_code: StatusCode, ) -> String { let error = ContextualError::HTTPAuthenticationError(Box::new(error)); @@ -149,6 +152,7 @@ fn build_unauthorized_response( renderer::render_error( &error.to_string(), + error_code, &return_path, None, None, -- cgit v1.2.3