From ccec64efaadb828940133d29c2ee4e9dd554aa91 Mon Sep 17 00:00:00 2001 From: Nicolas Auler Date: Tue, 17 Dec 2024 16:17:51 -0300 Subject: [PATCH] log: add json bytes to transaction list pluggy client api error log --- src/client/pluggy/transactions.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/client/pluggy/transactions.rs b/src/client/pluggy/transactions.rs index 26f5cfb..034c300 100644 --- a/src/client/pluggy/transactions.rs +++ b/src/client/pluggy/transactions.rs @@ -182,17 +182,25 @@ pub async fn list_transactions( .send() .await?; - let transactions: ListTransactionsResponse = match resp.status() { - StatusCode::OK => resp.json().await?, + match resp.status() { + StatusCode::OK => (), StatusCode::BAD_REQUEST => return Ok(ListTransactionsOutcome::Missing), StatusCode::INTERNAL_SERVER_ERROR => return Ok(ListTransactionsOutcome::Internal), _ => { - let res = resp.text().await?; - tracing::error!(?res, "received unexpected error from list transactions"); - bail!("unknown error: {}", res) + bail!("received unexpected status code from list transactions") } }; + let bytes = resp.bytes().await?; + let transactions: ListTransactionsResponse = serde_json::from_slice(&bytes).map_err(|e| { + tracing::error!( + ?e, + ?bytes, + "error deserializing transactions list from pluggy" + ); + e + })?; + Ok(ListTransactionsOutcome::Success(transactions)) }