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};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
// See https://github.com/MusicPlayerDaemon/MPD/blob/7774c3369e1484dc5dec6d7d9572e0a57e9c5302/src/command/AllCommands.cxx#L67-L209
|
// See https://github.com/MusicPlayerDaemon/MPD/blob/7774c3369e1484dc5dec6d7d9572e0a57e9c5302/src/command/AllCommands.cxx#L67-L209
|
||||||
pub enum Response {
|
pub type Response = Result<(), MpdError>;
|
||||||
Ok,
|
|
||||||
GenericError(String),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<()> for Response {
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
fn from(_: ()) -> Self {
|
pub enum ErrorCode {
|
||||||
Response::Ok
|
NotList = 1,
|
||||||
}
|
Arg = 2,
|
||||||
}
|
Password = 3,
|
||||||
|
Permission = 4,
|
||||||
|
Unknown = 5,
|
||||||
|
|
||||||
// impl From<Error> for Response {
|
NoExist = 50,
|
||||||
// fn from(e: Error) -> Self {
|
PlaylistMax = 51,
|
||||||
// Response::GenericError(e.to_string())
|
System = 52,
|
||||||
// }
|
PlaylistLoad = 53,
|
||||||
// }
|
UpdateAlready = 54,
|
||||||
|
PlayerSync = 55,
|
||||||
|
Exist = 56,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
pub struct GetFingerprintResponse {
|
pub struct MpdError {
|
||||||
pub chromaprint: String,
|
code: ErrorCode,
|
||||||
}
|
command: String,
|
||||||
|
message: String,
|
||||||
pub struct Neighbor {
|
command_list_num: usize,
|
||||||
pub neighbor: String,
|
|
||||||
pub name: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct NeighborResponse {
|
|
||||||
pub neighbors: Vec<Neighbor>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct UrlHandlersResponse {
|
|
||||||
pub url_handlers: Vec<String>,
|
|
||||||
}
|
}
|
||||||
|
@ -5,11 +5,11 @@ pub trait MPDServer {
|
|||||||
|
|
||||||
fn route_request(&mut self, request: Request) -> Result<Response, Self::Error> {
|
fn route_request(&mut self, request: Request) -> Result<Response, Self::Error> {
|
||||||
match request {
|
match request {
|
||||||
Request::ClearError => self.handle_clear_error().map(|_| Response::Ok),
|
Request::ClearError => self.handle_clear_error().map(|_| Ok(())),
|
||||||
Request::CurrentSong => self.handle_current_song().map(|_| Response::Ok),
|
Request::CurrentSong => self.handle_current_song().map(|_| Ok(())),
|
||||||
Request::Idle(subsystems) => self.handle_idle(subsystems).map(|_| Response::Ok),
|
Request::Idle(subsystems) => self.handle_idle(subsystems).map(|_| Ok(())),
|
||||||
Request::Status => self.handle_status().map(|_| Response::Ok),
|
Request::Status => self.handle_status().map(|_| Ok(())),
|
||||||
Request::Stats => self.handle_stats().map(|_| Response::Ok),
|
Request::Stats => self.handle_stats().map(|_| Ok(())),
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user