From e2ad04f4139d0f0aceb02c43b6913d17d11087ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20Pej=C5=A1a?= Date: Thu, 28 Mar 2019 18:32:15 +0100 Subject: Better error handling for file upload. --- src/errors.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/errors.rs') diff --git a/src/errors.rs b/src/errors.rs index 2aa5f58..f42cc02 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,6 +1,23 @@ use failure::{Backtrace, Context, Fail}; use std::fmt::{self, Debug, Display}; +/// Kinds of errors which might happen during file upload +#[derive(Debug, Fail)] +pub enum FileUploadErrorKind { + /// This error will occur when file overriding is off and file with same name already exists + #[fail(display = "File with this name already exists")] + FileExist, + /// This error will occur when server will fail to preccess http header during file upload + #[fail(display = "Failed to parse incoming request")] + ParseError, + /// This error will occur when we fail to precess multipart request + #[fail(display = "Failed to process multipart request")] + MultipartError(actix_web::error::MultipartError), + /// This error may occur when trying to write incoming file to disk + #[fail(display = "Failed to create or write to file")] + IOError(std::io::Error), +} + /// Kinds of errors which might happen during the generation of an archive #[derive(Debug, Fail)] pub enum CompressionErrorKind { -- cgit v1.2.3 From a13b26c1c90707056e5d4e36d67563fc91467871 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20Pej=C5=A1a?= Date: Thu, 28 Mar 2019 18:49:17 +0100 Subject: Check if we have permissions to create files. --- src/errors.rs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/errors.rs') diff --git a/src/errors.rs b/src/errors.rs index f42cc02..1eaa7c7 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -16,6 +16,9 @@ pub enum FileUploadErrorKind { /// This error may occur when trying to write incoming file to disk #[fail(display = "Failed to create or write to file")] IOError(std::io::Error), + /// This error will occur when we he have insuffictent permissions to create new file + #[fail(display = "Insuffitient permissions to create file")] + InsufficientPermissions, } /// Kinds of errors which might happen during the generation of an archive -- cgit v1.2.3 From 756a63200cdc48bf17d2997a2cbd537802a5193c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20Pej=C5=A1a?= Date: Fri, 29 Mar 2019 17:21:14 +0100 Subject: Fix typos --- src/errors.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/errors.rs') diff --git a/src/errors.rs b/src/errors.rs index 1eaa7c7..21d9e07 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -4,20 +4,20 @@ use std::fmt::{self, Debug, Display}; /// Kinds of errors which might happen during file upload #[derive(Debug, Fail)] pub enum FileUploadErrorKind { - /// This error will occur when file overriding is off and file with same name already exists + /// This error will occur when file overriding is off and a file with same name already exists #[fail(display = "File with this name already exists")] FileExist, - /// This error will occur when server will fail to preccess http header during file upload + /// This error will occur when the server fails to process the HTTP header during file upload #[fail(display = "Failed to parse incoming request")] ParseError, - /// This error will occur when we fail to precess multipart request + /// This error will occur when we fail to process the multipart request #[fail(display = "Failed to process multipart request")] MultipartError(actix_web::error::MultipartError), - /// This error may occur when trying to write incoming file to disk + /// This error may occur when trying to write the incoming file to disk #[fail(display = "Failed to create or write to file")] IOError(std::io::Error), /// This error will occur when we he have insuffictent permissions to create new file - #[fail(display = "Insuffitient permissions to create file")] + #[fail(display = "Insufficient permissions to create file")] InsufficientPermissions, } -- cgit v1.2.3