diff --git a/CHANGES.md b/CHANGES.md index cf4df3e36..db938c937 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,8 @@ * Add `Router::with_async()` method for async handler registration. +* Added error response functions for 501,502,503,504 + ## 0.6.2 (2018-05-09) diff --git a/build.rs b/build.rs index 7cb25c731..c8457944c 100644 --- a/build.rs +++ b/build.rs @@ -1,8 +1,6 @@ extern crate version_check; fn main() { - let mut has_impl_trait = true; - match version_check::is_min_version("1.26.0") { Some((true, _)) => println!("cargo:rustc-cfg=actix_impl_trait"), _ => (), diff --git a/src/error.rs b/src/error.rs index 2ad4f6b91..fe9796727 100644 --- a/src/error.rs +++ b/src/error.rs @@ -777,7 +777,6 @@ where InternalError::new(err, StatusCode::BAD_GATEWAY).into() } - /// Helper function that creates wrapper of any error and /// generate *SERVICE UNAVAILABLE* response. #[allow(non_snake_case)] @@ -798,7 +797,6 @@ where InternalError::new(err, StatusCode::GATEWAY_TIMEOUT).into() } - #[cfg(test)] mod tests { use super::*; @@ -954,4 +952,52 @@ mod tests { let resp: HttpResponse = err.error_response(); assert_eq!(resp.status(), StatusCode::OK); } + + #[test] + fn test_error_helpers() { + let r: HttpResponse = ErrorBadRequest("err").into(); + assert_eq!(r.status(), StatusCode::BAD_REQUEST); + + let r: HttpResponse = ErrorUnauthorized("err").into(); + assert_eq!(r.status(), StatusCode::UNAUTHORIZED); + + let r: HttpResponse = ErrorForbidden("err").into(); + assert_eq!(r.status(), StatusCode::FORBIDDEN); + + let r: HttpResponse = ErrorNotFound("err").into(); + assert_eq!(r.status(), StatusCode::NOT_FOUND); + + let r: HttpResponse = ErrorMethodNotAllowed("err").into(); + assert_eq!(r.status(), StatusCode::METHOD_NOT_ALLOWED); + + let r: HttpResponse = ErrorRequestTimeout("err").into(); + assert_eq!(r.status(), StatusCode::REQUEST_TIMEOUT); + + let r: HttpResponse = ErrorConflict("err").into(); + assert_eq!(r.status(), StatusCode::CONFLICT); + + let r: HttpResponse = ErrorGone("err").into(); + assert_eq!(r.status(), StatusCode::GONE); + + let r: HttpResponse = ErrorPreconditionFailed("err").into(); + assert_eq!(r.status(), StatusCode::PRECONDITION_FAILED); + + let r: HttpResponse = ErrorExpectationFailed("err").into(); + assert_eq!(r.status(), StatusCode::EXPECTATION_FAILED); + + let r: HttpResponse = ErrorInternalServerError("err").into(); + assert_eq!(r.status(), StatusCode::INTERNAL_SERVER_ERROR); + + let r: HttpResponse = ErrorNotImplemented("err").into(); + assert_eq!(r.status(), StatusCode::NOT_IMPLEMENTED); + + let r: HttpResponse = ErrorBadGateway("err").into(); + assert_eq!(r.status(), StatusCode::BAD_GATEWAY); + + let r: HttpResponse = ErrorServiceUnavailable("err").into(); + assert_eq!(r.status(), StatusCode::SERVICE_UNAVAILABLE); + + let r: HttpResponse = ErrorGatewayTimeout("err").into(); + assert_eq!(r.status(), StatusCode::GATEWAY_TIMEOUT); + } }