diff --git a/derive/src/resource_error.rs b/derive/src/resource_error.rs index b3af040..e2b78d0 100644 --- a/derive/src/resource_error.rs +++ b/derive/src/resource_error.rs @@ -231,7 +231,7 @@ pub fn expand_resource_error(input: DeriveInput) -> Result { let variants = inum.variants.into_iter().map(process_variant).collect_to_result()?; let display_impl = if variants.iter().any(|v| v.display.is_none()) { - None + None // TODO issue warning if display is present on some but not all } else { let were = generics.params.iter().filter_map(|param| match param { GenericParam::Type(ty) => { diff --git a/tests/resource_error.rs b/tests/resource_error.rs new file mode 100644 index 0000000..a00b08a --- /dev/null +++ b/tests/resource_error.rs @@ -0,0 +1,36 @@ +use gotham_restful::ResourceError; + +#[derive(ResourceError)] +enum Error { + #[display("I/O Error: {0}")] + IoError(#[from] std::io::Error), + + #[status(INTERNAL_SERVER_ERROR)] + #[display("Internal Server Error: {0}")] + InternalServerError(String) +} + +mod resource_error { + use super::Error; + use gotham::hyper::StatusCode; + use gotham_restful::IntoResponseError; + use mime::APPLICATION_JSON; + + #[test] + fn io_error() { + let err = Error::IoError(std::io::Error::last_os_error()); + let res = err.into_response_error().unwrap(); + assert_eq!(res.status, StatusCode::INTERNAL_SERVER_ERROR); + assert_eq!(res.mime, Some(APPLICATION_JSON)); + } + + #[test] + fn internal_server_error() { + let err = Error::InternalServerError("Brocken".to_owned()); + assert_eq!(&format!("{}", err), "Internal Server Error: Brocken"); + + let res = err.into_response_error().unwrap(); + assert_eq!(res.status, StatusCode::INTERNAL_SERVER_ERROR); + assert_eq!(res.mime, None); // TODO shouldn't this be a json error message? + } +}