From 6a9cd00275005db1b643a70ff72767bff34a2dd7 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Fri, 13 Dec 2024 18:29:54 +0100 Subject: [PATCH] response: remove leftover response types, add error codes --- src/response.rs | 50 +++++++++++++++++++++---------------------------- src/server.rs | 10 +++++----- 2 files changed, 26 insertions(+), 34 deletions(-) diff --git a/src/response.rs b/src/response.rs index c136d89..61e54c9 100644 --- a/src/response.rs +++ b/src/response.rs @@ -1,37 +1,29 @@ use serde::{Deserialize, Serialize}; // See https://github.com/MusicPlayerDaemon/MPD/blob/7774c3369e1484dc5dec6d7d9572e0a57e9c5302/src/command/AllCommands.cxx#L67-L209 -pub enum Response { - Ok, - GenericError(String), -} +pub type Response = Result<(), MpdError>; -impl From<()> for Response { - fn from(_: ()) -> Self { - Response::Ok - } -} +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] +pub enum ErrorCode { + NotList = 1, + Arg = 2, + Password = 3, + Permission = 4, + Unknown = 5, -// impl From for Response { -// fn from(e: Error) -> Self { -// Response::GenericError(e.to_string()) -// } -// } + NoExist = 50, + PlaylistMax = 51, + System = 52, + PlaylistLoad = 53, + UpdateAlready = 54, + PlayerSync = 55, + Exist = 56, +} #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] -pub struct GetFingerprintResponse { - pub chromaprint: String, -} - -pub struct Neighbor { - pub neighbor: String, - pub name: String, -} - -pub struct NeighborResponse { - pub neighbors: Vec, -} - -pub struct UrlHandlersResponse { - pub url_handlers: Vec, +pub struct MpdError { + code: ErrorCode, + command: String, + message: String, + command_list_num: usize, } diff --git a/src/server.rs b/src/server.rs index e1784ae..11f8309 100644 --- a/src/server.rs +++ b/src/server.rs @@ -5,11 +5,11 @@ pub trait MPDServer { fn route_request(&mut self, request: Request) -> Result { match request { - Request::ClearError => self.handle_clear_error().map(|_| Response::Ok), - Request::CurrentSong => self.handle_current_song().map(|_| Response::Ok), - Request::Idle(subsystems) => self.handle_idle(subsystems).map(|_| Response::Ok), - Request::Status => self.handle_status().map(|_| Response::Ok), - Request::Stats => self.handle_stats().map(|_| Response::Ok), + Request::ClearError => self.handle_clear_error().map(|_| Ok(())), + Request::CurrentSong => self.handle_current_song().map(|_| Ok(())), + Request::Idle(subsystems) => self.handle_idle(subsystems).map(|_| Ok(())), + Request::Status => self.handle_status().map(|_| Ok(())), + Request::Stats => self.handle_stats().map(|_| Ok(())), _ => unimplemented!(), } }