diff --git a/sources/api/apiclient/src/apply.rs b/sources/api/apiclient/src/apply.rs index 10d539cd304..4e53ad4d91f 100644 --- a/sources/api/apiclient/src/apply.rs +++ b/sources/api/apiclient/src/apply.rs @@ -44,12 +44,16 @@ where // Send the settings changes to the server in the same transaction. (They're quick local // requests, so don't add the complexity of making them run concurrently.) - for (_input_source, json) in changes { + for (input_source, json) in changes { let uri = format!("/settings?tx={}", transaction); let method = "PATCH"; let (_status, _body) = crate::raw_request(&socket_path, &uri, method, Some(json)) .await - .context(error::PatchSnafu)?; + .context(error::PatchSnafu { + input_source, + uri, + method, + })?; } // Commit the transaction and apply it to the system. @@ -192,8 +196,17 @@ mod error { #[snafu(display("Settings from '{}' are not a TOML table / JSON object", input_source))] ModelType { input_source: String }, - #[snafu(display("{}", source))] + #[snafu(display( + "Failed to {} settings from '{}' to '{}': {}", + method, + input_source, + uri, + source + ))] Patch { + input_source: String, + uri: String, + method: String, #[snafu(source(from(crate::Error, Box::new)))] source: Box, }, diff --git a/sources/api/apiclient/src/lib.rs b/sources/api/apiclient/src/lib.rs index 646c6a57a9a..8fcbf9697ca 100644 --- a/sources/api/apiclient/src/lib.rs +++ b/sources/api/apiclient/src/lib.rs @@ -39,9 +39,6 @@ mod error { #[snafu(display("Failed to send request: {}", source))] RequestSend { source: hyper::Error }, - #[snafu(display("{}", body))] - CliResponseStatus { body: String }, - #[snafu(display("Status {} when {}ing {}: {}", code.as_str(), method, uri, body))] ResponseStatus { method: String, @@ -89,7 +86,15 @@ where let (status, body) = raw_request_unchecked(&socket_path, &uri, &method, data).await?; // Error if the response status is in not in the 2xx range. - ensure!(status.is_success(), error::CliResponseStatusSnafu { body }); + ensure!( + status.is_success(), + error::ResponseStatusSnafu { + method: method.as_ref(), + code: status, + uri: uri.as_ref(), + body, + } + ); Ok((status, body)) } @@ -139,7 +144,6 @@ where .await .context(error::ResponseBodyReadSnafu)?; let body = String::from_utf8(body_bytes.to_vec()).context(error::NonUtf8ResponseSnafu)?; - Ok((status, body)) } diff --git a/sources/api/apiclient/src/set.rs b/sources/api/apiclient/src/set.rs index 0e6b6390602..ebd15fb6ef1 100644 --- a/sources/api/apiclient/src/set.rs +++ b/sources/api/apiclient/src/set.rs @@ -21,14 +21,14 @@ where let method = "PATCH"; let (_status, _body) = crate::raw_request(&socket_path, &uri, method, Some(settings_data)) .await - .context(error::RequestSnafu)?; + .context(error::RequestSnafu { uri, method })?; // Commit the transaction and apply it to the system. let uri = format!("/tx/commit_and_apply?tx={}", transaction); let method = "POST"; let (_status, _body) = crate::raw_request(&socket_path, &uri, method, None) .await - .context(error::RequestSnafu)?; + .context(error::RequestSnafu { uri, method })?; Ok(()) } @@ -42,8 +42,10 @@ mod error { #[snafu(display("Unable to serialize data: {}", source))] Serialize { source: serde_json::Error }, - #[snafu(display("{}", source))] + #[snafu(display("Failed {} request to '{}': {}", method, uri, source))] Request { + method: String, + uri: String, #[snafu(source(from(crate::Error, Box::new)))] source: Box, },