diff options
author | HampusM <hampus@hampusmat.com> | 2022-09-09 20:34:03 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-09-09 20:34:03 +0200 |
commit | c71ff70ffec328935b9ca4492e313b4a480d7ec7 (patch) | |
tree | 431ddb1c805787d1cec46384be98ffca1adccf56 /src/client.rs | |
parent | db42316544c65951c7781357ec5aaba1b9abb8ab (diff) |
fix: handle get auth token errors
Diffstat (limited to 'src/client.rs')
-rw-r--r-- | src/client.rs | 15 |
1 files changed, 12 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( |