mirror of
https://github.com/timvisee/ffsend.git
synced 2025-10-03 17:49:15 +02:00
Extract status code extention to module
This commit is contained in:
parent
e84ba364dc
commit
b7d8e49458
7 changed files with 23 additions and 34 deletions
|
@ -18,6 +18,7 @@ use serde_json;
|
||||||
use crypto::b64;
|
use crypto::b64;
|
||||||
use crypto::key_set::KeySet;
|
use crypto::key_set::KeySet;
|
||||||
use crypto::sign::signature_encoded;
|
use crypto::sign::signature_encoded;
|
||||||
|
use ext::status_code::StatusCodeExt;
|
||||||
use file::file::DownloadFile;
|
use file::file::DownloadFile;
|
||||||
use file::metadata::Metadata;
|
use file::metadata::Metadata;
|
||||||
use reader::{EncryptedFileWriter, ProgressReporter, ProgressWriter};
|
use reader::{EncryptedFileWriter, ProgressReporter, ProgressWriter};
|
||||||
|
@ -492,18 +493,3 @@ pub enum FileError {
|
||||||
#[fail(display = "Failed to create file decryptor")]
|
#[fail(display = "Failed to create file decryptor")]
|
||||||
EncryptedWriter,
|
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()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -23,16 +23,16 @@ use url::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use crypto::key_set::KeySet;
|
use crypto::key_set::KeySet;
|
||||||
|
use ext::status_code::StatusCodeExt;
|
||||||
|
use file::file::File as SendFile;
|
||||||
|
use file::metadata::{Metadata, XFileMetadata};
|
||||||
use reader::{
|
use reader::{
|
||||||
EncryptedFileReader,
|
EncryptedFileReader,
|
||||||
ExactLengthReader,
|
ExactLengthReader,
|
||||||
ProgressReader,
|
ProgressReader,
|
||||||
ProgressReporter,
|
ProgressReporter,
|
||||||
};
|
};
|
||||||
use file::file::File as SendFile;
|
|
||||||
use file::metadata::{Metadata, XFileMetadata};
|
|
||||||
|
|
||||||
// TODO: remove these specified types
|
|
||||||
type EncryptedReader = ProgressReader<BufReader<EncryptedFileReader>>;
|
type EncryptedReader = ProgressReader<BufReader<EncryptedFileReader>>;
|
||||||
|
|
||||||
/// A file upload action to a Send server.
|
/// A file upload action to a Send server.
|
||||||
|
@ -417,18 +417,3 @@ pub enum UploadError {
|
||||||
#[fail(display = "Failed to parse received URL")]
|
#[fail(display = "Failed to parse received URL")]
|
||||||
ParseUrl(#[cause] UrlParseError),
|
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
api/src/ext/mod.rs
Normal file
1
api/src/ext/mod.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
pub mod status_code;
|
15
api/src/ext/status_code.rs
Normal file
15
api/src/ext/status_code.rs
Normal file
|
@ -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()))
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,6 +13,7 @@ pub extern crate url;
|
||||||
|
|
||||||
pub mod action;
|
pub mod action;
|
||||||
pub mod crypto;
|
pub mod crypto;
|
||||||
|
mod ext;
|
||||||
pub mod file;
|
pub mod file;
|
||||||
pub mod reader;
|
pub mod reader;
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,8 @@ name = "ffsend"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["clipboard"]
|
default = ["clipboard"]
|
||||||
|
|
||||||
|
# Compile without colored output support
|
||||||
no-color = ["colored/no-color"]
|
no-color = ["colored/no-color"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use std::error::Error as StdError;
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue