diff --git a/rust_backend/crates/link/src/api.rs b/rust_backend/crates/link/src/api.rs index 76456b30e..b7666634c 100644 --- a/rust_backend/crates/link/src/api.rs +++ b/rust_backend/crates/link/src/api.rs @@ -98,7 +98,9 @@ async fn rest(state: &Arc, method: &str, request: http::Request }; subsonic::handle(&state.shared, request).await } - Err((code, message)) => subsonic::error_response(¶ms, code, message), + Err((code, message)) => { + subsonic::error_response(&state.shared.config.app_version, ¶ms, code, message) + } } } diff --git a/rust_backend/crates/link/src/subsonic.rs b/rust_backend/crates/link/src/subsonic.rs index 840df3d86..9574181db 100644 --- a/rust_backend/crates/link/src/subsonic.rs +++ b/rust_backend/crates/link/src/subsonic.rs @@ -117,12 +117,17 @@ pub async fn handle(shared: &Shared, request: SubsonicRequest) -> HttpResponse { } /// A Subsonic error response (`code` 0, 10, 40, 44, 70, ...), formatted per -/// the request's `f` parameter (JSON or XML). Without server state its -/// `serverVersion` is this crate's version. -pub fn error_response(params: &[(String, String)], code: u32, message: &str) -> HttpResponse { +/// the request's `f` parameter (JSON or XML). `server_version` is the app +/// version, as in every other response. +pub fn error_response( + server_version: &str, + params: &[(String, String)], + code: u32, + message: &str, +) -> HttpResponse { render( Format::of(params), - env!("CARGO_PKG_VERSION"), + server_version, Err(Failure::new(code, message)), ) } diff --git a/rust_backend/crates/link/src/subsonic/tests/browse.rs b/rust_backend/crates/link/src/subsonic/tests/browse.rs index b19357a9c..2953f83fb 100644 --- a/rust_backend/crates/link/src/subsonic/tests/browse.rs +++ b/rust_backend/crates/link/src/subsonic/tests/browse.rs @@ -62,6 +62,7 @@ async fn unknown_methods_and_bad_parameters_fail_with_http_200() { #[tokio::test] async fn error_response_follows_the_requested_format() { let json_reply = Reply::from(error_response( + "5.3.0", &[("f".to_owned(), "json".to_owned())], 40, "Wrong username or password", @@ -72,13 +73,14 @@ async fn error_response_follows_the_requested_format() { let response = json_reply.subsonic(); assert_eq!(response["status"], "failed"); assert_eq!(response["version"], "1.16.1"); + assert_eq!(response["serverVersion"], "5.3.0"); assert_eq!(response["type"], "mornye"); assert_eq!(response["openSubsonic"], true); assert_eq!( response["error"], json!({ "code": 40, "message": "Wrong username or password" }) ); - let xml_reply = Reply::from(error_response(&[], 44, "Invalid API key")).await; + let xml_reply = Reply::from(error_response("5.3.0", &[], 44, "Invalid API key")).await; assert_eq!(xml_reply.status, 200); assert_eq!(xml_reply.header("content-type"), Some(XML_TYPE)); let text = xml_reply.text();