diff --git a/nghe-backend/src/error/mod.rs b/nghe-backend/src/error/mod.rs index 80376b17..b647f654 100644 --- a/nghe-backend/src/error/mod.rs +++ b/nghe-backend/src/error/mod.rs @@ -315,8 +315,16 @@ impl From for Error { impl From 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, diff --git a/nghe-backend/src/lib.rs b/nghe-backend/src/lib.rs index 2673e9cc..1fe96af8 100644 --- a/nghe-backend/src/lib.rs +++ b/nghe-backend/src/lib.rs @@ -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)]