diff --git a/Cargo.toml b/Cargo.toml index 4bafeef..4e375b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "firebase-messaging-rs" -version = "0.6.1" +version = "0.7.0" authors = [ "Yoichiro ITO " ] diff --git a/src/lib.rs b/src/lib.rs index a283c9a..06a2f32 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,9 @@ pub mod topic; use async_trait::async_trait; -use gcloud_sdk::{GoogleAuthTokenGenerator, TokenSourceType, GCP_DEFAULT_SCOPES}; +use gcloud_sdk::{ + google::devtools::source, GoogleAuthTokenGenerator, TokenSourceType, GCP_DEFAULT_SCOPES, +}; use http::{ header::{ACCEPT, AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE}, Request, Response, StatusCode, @@ -147,8 +149,12 @@ pub trait GenericGoogleRestAPISupport { .await .map_err(|_| RPCError::DecodeFailure) .map_err(E::from)?; + let text = std::str::from_utf8(&buf).unwrap_or_default(); serde_json::from_slice::(&buf) - .map_err(|_| RPCError::DeserializeFailure) + .map_err(|e| RPCError::DeserializeFailure { + reason: format!("{e:?}"), + source: text.to_string(), + }) .map_err(E::from) } StatusCode::UNAUTHORIZED => { @@ -171,7 +177,7 @@ pub enum RPCError { BuildRequestFailure(String), HttpRequestFailure, DecodeFailure, - DeserializeFailure, + DeserializeFailure { reason: String, source: String }, InvalidRequest, Internal, Unknown(u16), diff --git a/src/topic.rs b/src/topic.rs index 3c8908c..a071c9e 100644 --- a/src/topic.rs +++ b/src/topic.rs @@ -148,8 +148,8 @@ impl From for TopicManagementError { RPCError::DecodeFailure => Self::InternalResponseError { msg: "unable to decode response body bytes".to_string(), }, - RPCError::DeserializeFailure => Self::InternalResponseError { - msg: "unable to deserialize response body to type".to_string(), + RPCError::DeserializeFailure { reason, source } => Self::InternalResponseError { + msg: format!("unable to deserialize response body to type: {reason}: {source}"), }, RPCError::Unauthorized(msg) => Self::Unauthorized(msg), RPCError::InvalidRequest => Self::InvalidRequest,