Skip to content

Commit 0e7ae48

Browse files
committed
use map_err
1 parent f32a02b commit 0e7ae48

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

dogstatsd/src/datadog.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ impl DdApi {
152152
pub async fn ship_series(&self, series: &Series) -> Result<Response, ShippingError> {
153153
let url = format!("{}/api/v2/series", &self.metrics_intake_url_prefix);
154154
let safe_body = serde_json::to_vec(&series)
155-
.map_err(|_| ShippingError::Payload("Failed to serialize series".to_string()))?;
155+
.map_err(|e| ShippingError::Payload(format!("Failed to serialize series: {e}")))?;
156156
debug!("Sending body: {:?}", &series);
157157
self.ship_data(url, safe_body, "application/json").await
158158
}
@@ -162,15 +162,12 @@ impl DdApi {
162162
sketches: &SketchPayload,
163163
) -> Result<Response, ShippingError> {
164164
let url = format!("{}/api/beta/sketches", &self.metrics_intake_url_prefix);
165-
if let Ok(safe_body) = sketches.write_to_bytes() {
166-
debug!("Sending distributions: {:?}", &sketches);
167-
self.ship_data(url, safe_body, "application/x-protobuf")
168-
.await
169-
} else {
170-
Err(ShippingError::Payload(
171-
"Failed to serialize sketches".to_string(),
172-
))
173-
}
165+
let safe_body = sketches
166+
.write_to_bytes()
167+
.map_err(|e| ShippingError::Payload(format!("Failed to serialize series: {e}")))?;
168+
debug!("Sending distributions: {:?}", &sketches);
169+
self.ship_data(url, safe_body, "application/x-protobuf")
170+
.await
174171
// TODO maybe go to coded output stream if we incrementally
175172
// add sketch payloads to the buffer
176173
// something like this, but fix the utf-8 encoding issue

0 commit comments

Comments
 (0)