Skip to content

Commit

Permalink
extract rspotify not found error
Browse files Browse the repository at this point in the history
  • Loading branch information
vnghia committed Dec 6, 2024
1 parent 35fdf70 commit bf8a41b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion nghe-backend/src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,16 @@ impl From<reqwest::Error> for Error {

impl From<rspotify::ClientError> for Error {
fn from(source: rspotify::ClientError) -> Self {
// TODO: Extract notfound error
let (status_code, opensubsonic_code) = match source {
rspotify::ClientError::Http(ref error) => match error.as_ref() {
rspotify::http::HttpError::Client(error)
if let Some(status) = error.status()
&& status == StatusCode::NOT_FOUND =>
{
(StatusCode::NOT_FOUND, OpensubsonicCode::TheRequestedDataWasNotFound)
}
_ => (StatusCode::INTERNAL_SERVER_ERROR, OpensubsonicCode::AGenericError),
},
rspotify::ClientError::Io(error) => return error.into(),
rspotify::ClientError::InvalidToken => (
StatusCode::UNAUTHORIZED,
Expand Down
1 change: 1 addition & 0 deletions nghe-backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#![feature(anonymous_lifetime_in_impl_trait)]
#![feature(async_closure)]
#![feature(duration_constructors)]
#![feature(if_let_guard)]
#![feature(integer_sign_cast)]
#![feature(iterator_try_collect)]
#![feature(let_chains)]
Expand Down

0 comments on commit bf8a41b

Please sign in to comment.