From cb63f207258071ade7f300dc63e9ed8cb98a1353 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Thu, 21 Jun 2018 11:41:15 -0700 Subject: actually log errors --- rust/Cargo.lock | 1 + rust/Cargo.toml | 1 + rust/src/api_server.rs | 42 ++++++++++++++++++++++++++++++------------ rust/src/lib.rs | 2 ++ 4 files changed, 34 insertions(+), 12 deletions(-) (limited to 'rust') diff --git a/rust/Cargo.lock b/rust/Cargo.lock index cdbdd1d8..c8dc516f 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -302,6 +302,7 @@ dependencies = [ "iron 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "iron-slog 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "iron-test 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)", "slog 2.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "slog-async 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 5870de64..1a584d84 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -14,6 +14,7 @@ dotenv = "0.9.0" clap = "*" error-chain = "0.11" uuid = "0.5" +log = "*" # API server chrono = { version = "0.4", features = ["serde"] } diff --git a/rust/src/api_server.rs b/rust/src/api_server.rs index 4c0f069e..c8b1f012 100644 --- a/rust/src/api_server.rs +++ b/rust/src/api_server.rs @@ -42,7 +42,10 @@ macro_rules! wrap_entity_handlers { $get_resp::NotFound(ErrorResponse { message: format!("No such entity {}: {}", stringify!($model), id) }), Err(Error(ErrorKind::Uuid(e), _)) => $get_resp::BadRequest(ErrorResponse { message: e.to_string() }), - Err(e) => $get_resp::GenericError(ErrorResponse { message: e.to_string() }), + Err(e) => { + error!("{}", e); + $get_resp::GenericError(ErrorResponse { message: e.to_string() }) + }, }; Box::new(futures::done(Ok(ret))) } @@ -59,7 +62,10 @@ macro_rules! wrap_entity_handlers { $post_resp::BadRequest(ErrorResponse { message: e.to_string() }), Err(Error(ErrorKind::Uuid(e), _)) => $post_resp::BadRequest(ErrorResponse { message: e.to_string() }), - Err(e) => $post_resp::GenericError(ErrorResponse { message: e.to_string() }), + Err(e) => { + error!("{}", e); + $post_resp::GenericError(ErrorResponse { message: e.to_string() }) + }, }; Box::new(futures::done(Ok(ret))) } @@ -76,7 +82,10 @@ macro_rules! wrap_entity_handlers { $post_batch_resp::BadRequest(ErrorResponse { message: e.to_string() }), Err(Error(ErrorKind::Uuid(e), _)) => $post_batch_resp::BadRequest(ErrorResponse { message: e.to_string() }), - Err(e) => $post_batch_resp::GenericError(ErrorResponse { message: e.to_string() }), + Err(e) => { + error!("{}", e); + $post_batch_resp::GenericError(ErrorResponse { message: e.to_string() }) + }, }; Box::new(futures::done(Ok(ret))) } @@ -110,8 +119,10 @@ macro_rules! wrap_lookup_handler { $get_resp::FoundEntity(entity), Err(Error(ErrorKind::Diesel(::diesel::result::Error::NotFound), _)) => $get_resp::NotFound(ErrorResponse { message: format!("Not found: {}", $idname) }), - Err(e) => - $get_resp::BadRequest(ErrorResponse { message: e.to_string() }), + Err(e) => { + error!("{}", e); + $get_resp::BadRequest(ErrorResponse { message: e.to_string() }) + }, }; Box::new(futures::done(Ok(ret))) } @@ -1153,10 +1164,12 @@ impl Api for Server { Err(Error(ErrorKind::Diesel(::diesel::result::Error::NotFound), _)) => GetEditorChangelogResponse::NotFound( ErrorResponse { message: format!("No such editor: {}", username.clone()) }), - Err(e) => + Err(e) => { // TODO: dig in to error type here + error!("{}", e); GetEditorChangelogResponse::GenericError( - ErrorResponse { message: e.to_string() }), + ErrorResponse { message: e.to_string() }) + }, }; Box::new(futures::done(Ok(ret))) } @@ -1172,9 +1185,11 @@ impl Api for Server { Err(Error(ErrorKind::Diesel(::diesel::result::Error::NotFound), _)) => GetEditorResponse::NotFound( ErrorResponse { message: format!("No such editor: {}", username.clone()) }), - Err(e) => + Err(e) => { // TODO: dig in to error type here - GetEditorResponse::GenericError(ErrorResponse { message: e.to_string() }), + error!("{}", e); + GetEditorResponse::GenericError(ErrorResponse { message: e.to_string() }) + }, }; Box::new(futures::done(Ok(ret))) } @@ -1186,9 +1201,12 @@ impl Api for Server { ) -> Box + Send> { let ret = match self.get_stats_handler(more.clone()) { Ok(stats) => GetStatsResponse::Success(stats), - Err(e) => GetStatsResponse::GenericError(ErrorResponse { - message: e.to_string(), - }), + Err(e) => { + error!("{}", e); + GetStatsResponse::GenericError(ErrorResponse { + message: e.to_string(), + }) + }, }; Box::new(futures::done(Ok(ret))) } diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 8334b3a5..d81035cc 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -14,6 +14,8 @@ extern crate error_chain; extern crate iron; #[macro_use] extern crate serde_json; +#[macro_use] +extern crate log; pub mod api_helpers; pub mod api_server; -- cgit v1.2.3