fix(link): report the app version in Subsonic auth errors

Errors before authentication used the crate version (0.1.0) while every
other response carried the app version.
This commit is contained in:
zarzet committed 2026-10-25 04:01:54 +07:00
1 parent 01c6fd53e5
commit 758ea77327
3 files changed
+15 -6

No files matched your search

+3 -1
View File
@@ -98,7 +98,9 @@ async fn rest(state: &Arc<State>, method: &str, request: http::Request<Incoming>
};
subsonic::handle(&state.shared, request).await
}
Err((code, message)) => subsonic::error_response(&params, code, message),
Err((code, message)) => {
subsonic::error_response(&state.shared.config.app_version, &params, code, message)
}
}
}
+9 -4
View File
@@ -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)),
)
}
@@ -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();