diff --git a/apps/ai-game-creator-shell/src-tauri/src/account_api.rs b/apps/ai-game-creator-shell/src-tauri/src/account_api.rs index a8a05391d..9c2caee3e 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/account_api.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/account_api.rs @@ -67,26 +67,23 @@ fn bounded_business_id(value: &str, label: &str) -> Result { Ok(value.to_string()) } -fn error_message(body: &str) -> Option { +fn error_field(body: &str, field: &str) -> Option { let value = serde_json::from_str::(body).ok()?; let error = value.get("error").unwrap_or(&value); error - .get("message") + .get(field) .and_then(Value::as_str) .map(str::trim) - .filter(|message| !message.is_empty()) + .filter(|detail| !detail.is_empty()) .map(ToString::to_string) } +fn error_message(body: &str) -> Option { + error_field(body, "message") +} + fn error_code(body: &str) -> Option { - let value = serde_json::from_str::(body).ok()?; - let error = value.get("error").unwrap_or(&value); - error - .get("code") - .and_then(Value::as_str) - .map(str::trim) - .filter(|code| !code.is_empty()) - .map(ToString::to_string) + error_field(body, "code") } fn map_http_error(status: StatusCode, body: &str, fallback: &str) -> String {