summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client.rs15
-rw-r--r--src/errors/client.rs10
2 files changed, 22 insertions, 3 deletions
diff --git a/src/client.rs b/src/client.rs
index 179377f..b814a52 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -198,10 +198,19 @@ impl DeezerClient
return Err(DeezerClientError::ReceivedErrorResponse(err_body.error));
}
- let access_token_response: AccessTokenResponse = serde_json::from_slice(body_buf)
- .map_err(DeezerClientError::ParseResponseFailed)?;
+ let access_token_response_result =
+ serde_json::from_slice::<AccessTokenResponse>(body_buf);
+
+ if let Ok(access_token_response) = access_token_response_result {
+ Ok(access_token_response.into())
+ } else {
+ let body_str = std::str::from_utf8(body_buf)
+ .map_err(|_| DeezerClientError::AuthErrorResponseNotUTF8)?;
- Ok(access_token_response.into())
+ Err(DeezerClientError::ReceivedAuthErrorResponse(
+ body_str.to_string(),
+ ))
+ }
}
fn build_endpoint_uri(
diff --git a/src/errors/client.rs b/src/errors/client.rs
index c3397e3..6eb7e68 100644
--- a/src/errors/client.rs
+++ b/src/errors/client.rs
@@ -18,6 +18,16 @@ pub enum DeezerClientError
#[error("Received a error response from the Deezer API")]
ReceivedErrorResponse(DeezerError),
+ /// Received a authentication error response from the Deezer.
+ #[error("Received a authentication error response from the Deezer")]
+ ReceivedAuthErrorResponse(String),
+
+ /// Received a authentication error response from the Deezer that's not valid UTF-8.
+ #[error(
+ "Received a authentication error response from the Deezer that's not valid UTF-8"
+ )]
+ AuthErrorResponseNotUTF8,
+
/// Failed to build API endpoint URI.
#[error("Failed to build API endpoint URI")]
BuildAPIEndpointURIFailed,