Browse Source

Extract status code extention to module

timvisee 7 years ago
parent
commit
b7d8e49458

+ 1 - 15
api/src/action/download.rs

@@ -18,6 +18,7 @@ use serde_json;
 use crypto::b64;
 use crypto::key_set::KeySet;
 use crypto::sign::signature_encoded;
+use ext::status_code::StatusCodeExt;
 use file::file::DownloadFile;
 use file::metadata::Metadata;
 use reader::{EncryptedFileWriter, ProgressReporter, ProgressWriter};
@@ -492,18 +493,3 @@ pub enum FileError {
     #[fail(display = "Failed to create file decryptor")]
     EncryptedWriter,
 }
-
-/// Reqwest status code extention, to easily retrieve an error message.
-// TODO: implement this globally somewhere
-trait StatusCodeExt {
-    /// Build a basic error message based on the status code.
-    fn err_text(&self) -> String;
-}
-
-impl StatusCodeExt for StatusCode {
-    fn err_text(&self) -> String {
-        self.canonical_reason()
-            .map(|text| text.to_owned())
-            .unwrap_or(format!("{}", self.as_u16()))
-    }
-}

+ 3 - 18
api/src/action/upload.rs

@@ -23,16 +23,16 @@ use url::{
 };
 
 use crypto::key_set::KeySet;
+use ext::status_code::StatusCodeExt;
+use file::file::File as SendFile;
+use file::metadata::{Metadata, XFileMetadata};
 use reader::{
     EncryptedFileReader,
     ExactLengthReader,
     ProgressReader,
     ProgressReporter,
 };
-use file::file::File as SendFile;
-use file::metadata::{Metadata, XFileMetadata};
 
-// TODO: remove these specified types
 type EncryptedReader = ProgressReader<BufReader<EncryptedFileReader>>;
 
 /// A file upload action to a Send server.
@@ -417,18 +417,3 @@ pub enum UploadError {
     #[fail(display = "Failed to parse received URL")]
     ParseUrl(#[cause] UrlParseError),
 }
-
-/// Reqwest status code extention, to easily retrieve an error message.
-// TODO: implement this globally somewhere
-trait StatusCodeExt {
-    /// Build a basic error message based on the status code.
-    fn err_text(&self) -> String;
-}
-
-impl StatusCodeExt for StatusCode {
-    fn err_text(&self) -> String {
-        self.canonical_reason()
-            .map(|text| text.to_owned())
-            .unwrap_or(format!("{}", self.as_u16()))
-    }
-}

+ 1 - 0
api/src/ext/mod.rs

@@ -0,0 +1 @@
+pub mod status_code;

+ 15 - 0
api/src/ext/status_code.rs

@@ -0,0 +1,15 @@
+use reqwest::StatusCode;
+
+/// Reqwest status code extention, to easily retrieve an error message.
+pub trait StatusCodeExt {
+    /// Build a basic error message based on the status code.
+    fn err_text(&self) -> String;
+}
+
+impl StatusCodeExt for StatusCode {
+    fn err_text(&self) -> String {
+        self.canonical_reason()
+            .map(|text| text.to_owned())
+            .unwrap_or(format!("{}", self.as_u16()))
+    }
+}

+ 1 - 0
api/src/lib.rs

@@ -13,6 +13,7 @@ pub extern crate url;
 
 pub mod action;
 pub mod crypto;
+mod ext;
 pub mod file;
 pub mod reader;
 

+ 2 - 0
cli/Cargo.toml

@@ -10,6 +10,8 @@ name = "ffsend"
 
 [features]
 default = ["clipboard"]
+
+# Compile without colored output support
 no-color = ["colored/no-color"]
 
 [dependencies]

+ 0 - 1
cli/src/action/upload.rs

@@ -1,4 +1,3 @@
-use std::error::Error as StdError;
 use std::path::Path;
 use std::sync::{Arc, Mutex};