From 786a0e3e079469b0d57d7d870ec6dbfd6b921f7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20Pej=C5=A1a?= Date: Tue, 9 Apr 2019 20:57:57 +0200 Subject: Change HTTP response code and cleanup previus commit. --- src/file_upload.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/file_upload.rs b/src/file_upload.rs index 5ef793d..4a0ae1f 100644 --- a/src/file_upload.rs +++ b/src/file_upload.rs @@ -105,9 +105,10 @@ pub fn upload_file(req: &HttpRequest) -> FutureResponse< .to_str() .unwrap_or("/") .to_owned(); - let app_root_dir = match req.state().path.canonicalize() { - Ok(path) => path, - Err(_) => return Box::new(create_error_response("Internal server error", &return_path)), + let app_root_dir = if let Ok(dir) = req.state().path.canonicalize() { + dir + } else { + return Box::new(create_error_response("Internal server error", &return_path)); }; let path = match Query::::extract(req) { Ok(query) => { @@ -151,13 +152,13 @@ pub fn upload_file(req: &HttpRequest) -> FutureResponse< ) } -// Convenience method for creating response errors, when file upload fails. +/// Convenience method for creating response errors, if file upload fails. fn create_error_response( description: &str, return_path: &str, ) -> FutureResult { future::ok( - HttpResponse::NotAcceptable() + HttpResponse::BadRequest() .content_type("text/html; charset=utf-8") .body(file_upload_error(description, return_path).into_string()), ) -- cgit v1.2.3