From bf8a41b135b2f8de3a2a36422364d89e99d98de2 Mon Sep 17 00:00:00 2001 From: Vo Van Nghia Date: Fri, 6 Dec 2024 16:05:41 +0100 Subject: [PATCH] extract rspotify not found error --- nghe-backend/src/error/mod.rs | 10 +++++++++- nghe-backend/src/lib.rs | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) 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)]