actix_ratelimit/
errors.rs

1//! Errors that can occur during middleware processing stage
2use actix_web::error::Error as AWError;
3use actix_web::web::HttpResponse;
4use failure::{self, Fail};
5use log::*;
6
7/// Custom error type. Useful for logging and debugging different kinds of errors.
8/// This type can be converted to Actix Error, which defaults to
9/// InternalServerError
10///
11#[derive(Debug, Fail)]
12pub enum ARError {
13    /// Store is not connected
14    #[fail(display = "store not connected")]
15    NotConnected,
16
17    /// Store is disconnected after initial successful connection
18    #[fail(display = "store disconnected")]
19    Disconnected,
20
21    /// Read/Write error on store
22    #[fail(display = "read/write operatiion failed: {}", _0)]
23    ReadWriteError(String),
24
25    /// Could be any kind of IO error
26    #[fail(display = "unknown error: {}", _0)]
27    UnknownError(std::io::Error),
28
29    /// Identifier error
30    #[fail(display = "client identification failed")]
31    IdentificationError,
32}
33
34impl From<ARError> for AWError {
35    fn from(err: ARError) -> AWError {
36        error!("{}", &err);
37        HttpResponse::InternalServerError().into()
38    }
39}