use night_fury_daemon_core::protocol::Response;
pub fn ok_json<T: serde::Serialize>(id: &str, value: &T) -> Response {
match serde_json::to_value(value) {
Ok(v) => Response::ok(id, v),
Err(e) => Response::err(id, format!("serialize error: {e}")),
}
}
pub fn ok_value(id: &str, value: serde_json::Value) -> Response {
Response::ok(id, value)
}
pub fn err_str(id: &str, msg: impl Into<String>) -> Response {
Response::err(id, msg.into())
}
pub fn to_response<T: serde::Serialize>(
id: &str,
result: Result<T, tail_fin_common::TailFinError>,
) -> Response {
match result {
Ok(value) => ok_json(id, &value),
Err(e) => err_str(id, e.to_string()),
}
}