(response: gloo_net::http::Response)
| 2550 | |
| 2551 | #[cfg(not(feature = "mock"))] |
| 2552 | async fn parse_admin_gpt2api_rs_response<T>(response: gloo_net::http::Response) -> Result<T, String> |
| 2553 | where |
| 2554 | T: DeserializeOwned, |
| 2555 | { |
| 2556 | if !response.ok() { |
| 2557 | let text = response.text().await.unwrap_or_default(); |
| 2558 | return Err(format!("Failed: {text}")); |
| 2559 | } |
| 2560 | // Guard against SPA fallback returning index.html with a 200. Without this |
| 2561 | // check, `response.json()` on the HTML body surfaces as the cryptic |
| 2562 | // "Parse error: SerdeError(expected value)" banner. Surface a clearer |
| 2563 | // message so the operator knows the gpt2api-rs integration is missing on |
| 2564 | // the backend rather than chasing a phantom JSON bug. |
| 2565 | let content_type = response |
| 2566 | .headers() |
| 2567 | .get("content-type") |
| 2568 | .unwrap_or_default() |
| 2569 | .to_lowercase(); |
| 2570 | if !content_type.contains("application/json") { |
| 2571 | return Err("gpt2api-rs admin endpoint is not available on this backend (got a non-JSON \ |
| 2572 | response). Ensure the gpt2api-rs integration is enabled on the server build." |
| 2573 | .to_string()); |
| 2574 | } |
| 2575 | response |
| 2576 | .json() |
| 2577 | .await |
| 2578 | .map_err(|e| format!("Parse error: {:?}", e)) |
| 2579 | } |
| 2580 | |
| 2581 | #[cfg(not(feature = "mock"))] |
| 2582 | async fn get_admin_gpt2api_rs<T>(path: &str) -> Result<T, String> |
no test coverage detected