response: remove leftover response types, add error codes
This commit is contained in:
parent
9cb92741a4
commit
6a9cd00275
@ -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,
|
||||
}
|
||||
|
@ -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!(),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user