diff --git a/CHANGES.md b/CHANGES.md index 6c4a4aa9a..0c19ba0f6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,7 +2,7 @@ ## 0.4.10 (2018-03-xx) -.. +* Use `Error` instead of `InternalError` for `error::ErrorXXXX` methods ## 0.4.9 (2018-03-16) diff --git a/src/context.rs b/src/context.rs index aa6f4c49a..fda5a65f5 100644 --- a/src/context.rs +++ b/src/context.rs @@ -191,7 +191,7 @@ impl ActorHttpContext for HttpContext where A: Actor, if self.inner.alive() { match self.inner.poll(ctx) { Ok(Async::NotReady) | Ok(Async::Ready(())) => (), - Err(_) => return Err(ErrorInternalServerError("error").into()), + Err(_) => return Err(ErrorInternalServerError("error")), } } diff --git a/src/error.rs b/src/error.rs index 40ecf7045..98c48cbcc 100644 --- a/src/error.rs +++ b/src/error.rs @@ -575,68 +575,91 @@ impl Responder for InternalError /// Helper function that creates wrapper of any error and generate *BAD REQUEST* response. #[allow(non_snake_case)] -pub fn ErrorBadRequest(err: T) -> InternalError { - InternalError::new(err, StatusCode::BAD_REQUEST) +pub fn ErrorBadRequest(err: T) -> Error + where T: Send + Sync + fmt::Debug + 'static +{ + InternalError::new(err, StatusCode::BAD_REQUEST).into() } /// Helper function that creates wrapper of any error and generate *UNAUTHORIZED* response. #[allow(non_snake_case)] -pub fn ErrorUnauthorized(err: T) -> InternalError { - InternalError::new(err, StatusCode::UNAUTHORIZED) +pub fn ErrorUnauthorized(err: T) -> Error + where T: Send + Sync + fmt::Debug + 'static +{ + InternalError::new(err, StatusCode::UNAUTHORIZED).into() } /// Helper function that creates wrapper of any error and generate *FORBIDDEN* response. #[allow(non_snake_case)] -pub fn ErrorForbidden(err: T) -> InternalError { - InternalError::new(err, StatusCode::FORBIDDEN) +pub fn ErrorForbidden(err: T) -> Error + where T: Send + Sync + fmt::Debug + 'static +{ + InternalError::new(err, StatusCode::FORBIDDEN).into() } /// Helper function that creates wrapper of any error and generate *NOT FOUND* response. #[allow(non_snake_case)] -pub fn ErrorNotFound(err: T) -> InternalError { - InternalError::new(err, StatusCode::NOT_FOUND) +pub fn ErrorNotFound(err: T) -> Error + where T: Send + Sync + fmt::Debug + 'static +{ + InternalError::new(err, StatusCode::NOT_FOUND).into() } /// Helper function that creates wrapper of any error and generate *METHOD NOT ALLOWED* response. #[allow(non_snake_case)] -pub fn ErrorMethodNotAllowed(err: T) -> InternalError { - InternalError::new(err, StatusCode::METHOD_NOT_ALLOWED) +pub fn ErrorMethodNotAllowed(err: T) -> Error + where T: Send + Sync + fmt::Debug + 'static +{ + InternalError::new(err, StatusCode::METHOD_NOT_ALLOWED).into() } /// Helper function that creates wrapper of any error and generate *REQUEST TIMEOUT* response. #[allow(non_snake_case)] -pub fn ErrorRequestTimeout(err: T) -> InternalError { - InternalError::new(err, StatusCode::REQUEST_TIMEOUT) +pub fn ErrorRequestTimeout(err: T) -> Error + where T: Send + Sync + fmt::Debug + 'static +{ + InternalError::new(err, StatusCode::REQUEST_TIMEOUT).into() } /// Helper function that creates wrapper of any error and generate *CONFLICT* response. #[allow(non_snake_case)] -pub fn ErrorConflict(err: T) -> InternalError { - InternalError::new(err, StatusCode::CONFLICT) +pub fn ErrorConflict(err: T) -> Error + where T: Send + Sync + fmt::Debug + 'static +{ + InternalError::new(err, StatusCode::CONFLICT).into() } /// Helper function that creates wrapper of any error and generate *GONE* response. #[allow(non_snake_case)] -pub fn ErrorGone(err: T) -> InternalError { - InternalError::new(err, StatusCode::GONE) +pub fn ErrorGone(err: T) -> Error + where T: Send + Sync + fmt::Debug + 'static +{ + InternalError::new(err, StatusCode::GONE).into() } /// Helper function that creates wrapper of any error and generate *PRECONDITION FAILED* response. #[allow(non_snake_case)] -pub fn ErrorPreconditionFailed(err: T) -> InternalError { - InternalError::new(err, StatusCode::PRECONDITION_FAILED) +pub fn ErrorPreconditionFailed(err: T) -> Error + where T: Send + Sync + fmt::Debug + 'static +{ + InternalError::new(err, StatusCode::PRECONDITION_FAILED).into() } /// Helper function that creates wrapper of any error and generate *EXPECTATION FAILED* response. #[allow(non_snake_case)] -pub fn ErrorExpectationFailed(err: T) -> InternalError { - InternalError::new(err, StatusCode::EXPECTATION_FAILED) +pub fn ErrorExpectationFailed(err: T) -> Error + where T: Send + Sync + fmt::Debug + 'static +{ + InternalError::new(err, StatusCode::EXPECTATION_FAILED).into() } -/// Helper function that creates wrapper of any error and generate *INTERNAL SERVER ERROR* response. +/// Helper function that creates wrapper of any error and +/// generate *INTERNAL SERVER ERROR* response. #[allow(non_snake_case)] -pub fn ErrorInternalServerError(err: T) -> InternalError { - InternalError::new(err, StatusCode::INTERNAL_SERVER_ERROR) +pub fn ErrorInternalServerError(err: T) -> Error + where T: Send + Sync + fmt::Debug + 'static +{ + InternalError::new(err, StatusCode::INTERNAL_SERVER_ERROR).into() } #[cfg(test)] diff --git a/src/param.rs b/src/param.rs index 1bb89d2db..a062bd096 100644 --- a/src/param.rs +++ b/src/param.rs @@ -4,9 +4,10 @@ use std::path::PathBuf; use std::str::FromStr; use std::slice::Iter; use std::borrow::Cow; +use http::StatusCode; use smallvec::SmallVec; -use error::{ResponseError, UriSegmentError, InternalError, ErrorBadRequest}; +use error::{ResponseError, UriSegmentError, InternalError}; /// A trait to abstract the idea of creating a new instance of a type from a path parameter. @@ -144,7 +145,8 @@ macro_rules! FROM_STR { type Err = InternalError<<$type as FromStr>::Err>; fn from_param(val: &str) -> Result { - <$type as FromStr>::from_str(val).map_err(ErrorBadRequest) + <$type as FromStr>::from_str(val) + .map_err(|e| InternalError::new(e, StatusCode::BAD_REQUEST)) } } } diff --git a/src/ws/context.rs b/src/ws/context.rs index 4b0775f6a..481ff5c06 100644 --- a/src/ws/context.rs +++ b/src/ws/context.rs @@ -205,7 +205,7 @@ impl ActorHttpContext for WebsocketContext where A: Actor