fix(arr): name the field, not a reply, in the 422
The backend's Malformed Display describes an answer that came back wrong. Nothing is sent while validating a settings write, so only the reason belongs in the message.
This commit is contained in:
@@ -107,8 +107,16 @@ impl SubtitleSettingsInput {
|
||||
// quietly stopped working. Validated whether or not this build
|
||||
// compiled the backend in — the column exists either way.
|
||||
if let Some(base_url) = blank_to_none(self.openai_base_url.as_deref()) {
|
||||
arr_subs::OpenAiEndpoint::new(Some(base_url), None)
|
||||
.map_err(|error| format!("openai_base_url: {error}"))?;
|
||||
arr_subs::OpenAiEndpoint::new(Some(base_url), None).map_err(|error| {
|
||||
// The backend's own Display talks about a reply that came
|
||||
// back wrong; here nothing was ever sent, so only the
|
||||
// reason belongs in the message.
|
||||
let reason = match &error {
|
||||
arr_subs::translate::Error::Malformed { detail, .. } => detail.clone(),
|
||||
other => other.to_string(),
|
||||
};
|
||||
format!("openai_base_url: {reason}")
|
||||
})?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -592,12 +600,9 @@ mod tests {
|
||||
.expect("put settings");
|
||||
assert_eq!(response.status(), StatusCode::UNPROCESSABLE_ENTITY);
|
||||
let body: serde_json::Value = response.json().await.expect("error json");
|
||||
assert!(
|
||||
body["error"]
|
||||
.as_str()
|
||||
.expect("error string")
|
||||
.starts_with("openai_base_url:"),
|
||||
"got {body}"
|
||||
assert_eq!(
|
||||
body["error"], "openai_base_url: bad base URL: relative URL without a base",
|
||||
"the message names the field and the reason, not a reply that never came"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user