refactor(errors): Move almost everything to RequestError.

This is nicer than stupid Box<dyn Error+Send> everywhere.
This commit is contained in:
Lewin Bormann
2019-06-22 21:53:55 +02:00
parent 8d6085375f
commit 602ea1565d
8 changed files with 178 additions and 198 deletions

View File

@@ -4,7 +4,7 @@ use std::error::Error;
use std::fmt;
use std::io;
use crate::types::RequestError;
use crate::types::{PollError, RequestError};
use chrono::{DateTime, Local, Utc};
use std::time::Duration;
@@ -45,21 +45,6 @@ impl fmt::Display for PollInformation {
}
}
/// Encapsulates all possible results of a `poll_token(...)` operation
#[derive(Debug)]
pub enum PollError {
/// Connection failure - retry if you think it's worth it
HttpError(hyper::Error),
/// Indicates we are expired, including the expiration date
Expired(DateTime<Utc>),
/// Indicates that the user declined access. String is server response
AccessDenied,
/// Indicates that too many attempts failed.
TimedOut,
/// Other type of error.
Other(String),
}
impl fmt::Display for PollError {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
match *self {
@@ -93,13 +78,6 @@ pub trait AuthenticatorDelegate: Clone {
Retry::Abort
}
/// Called whenever there is an HttpError, usually if there are network problems.
///
/// Return retry information.
fn connection_error(&mut self, _: &hyper::http::Error) -> Retry {
Retry::Abort
}
/// Called whenever we failed to retrieve a token or set a token due to a storage error.
/// You may use it to either ignore the incident or retry.
/// This can be useful if the underlying `TokenStorage` may fail occasionally.