1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-08-31 00:50:20 +02:00

map BlockingError

This commit is contained in:
Nikolay Kim
2019-03-11 23:19:05 -07:00
parent a2c4639074
commit 7242d96701
3 changed files with 31 additions and 11 deletions

View File

@@ -1,4 +1,5 @@
//! Error and Result module
use std::fmt;
pub use actix_http::error::*;
use derive_more::{Display, From};
@@ -20,3 +21,23 @@ pub enum UrlGenerationError {
/// `InternalServerError` for `UrlGeneratorError`
impl ResponseError for UrlGenerationError {}
/// Blocking operation execution error
#[derive(Debug, Display)]
pub enum BlockingError<E: fmt::Debug> {
#[display(fmt = "{:?}", _0)]
Error(E),
#[display(fmt = "Thread pool is gone")]
Canceled,
}
impl<E: fmt::Debug> ResponseError for BlockingError<E> {}
impl<E: fmt::Debug> From<actix_rt::blocking::BlockingError<E>> for BlockingError<E> {
fn from(err: actix_rt::blocking::BlockingError<E>) -> Self {
match err {
actix_rt::blocking::BlockingError::Error(e) => BlockingError::Error(e),
actix_rt::blocking::BlockingError::Canceled => BlockingError::Canceled,
}
}
}