response: remove leftover response types, add error codes
Some checks failed
Build and test / check (push) Failing after 1m2s
Build and test / build (push) Successful in 1m3s
Build and test / test (push) Successful in 1m37s
Build and test / docs (push) Successful in 1m16s

This commit is contained in:
Oystein Kristoffer Tveit 2024-12-13 18:29:54 +01:00
parent 9cb92741a4
commit 6a9cd00275
Signed by: oysteikt
GPG Key ID: 9F2F7D8250F35146
2 changed files with 26 additions and 34 deletions

View File

@ -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<Error> 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<Neighbor>,
}
pub struct UrlHandlersResponse {
pub url_handlers: Vec<String>,
pub struct MpdError {
code: ErrorCode,
command: String,
message: String,
command_list_num: usize,
}

View File

@ -5,11 +5,11 @@ pub trait MPDServer {
fn route_request(&mut self, request: Request) -> Result<Response, Self::Error> {
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!(),
}
}