(resp, dt)
| 300 | |
| 301 | |
| 302 | def classify(resp, dt) -> tuple[str, str]: |
| 303 | if resp is None: |
| 304 | return "BAD", "no response" |
| 305 | if isinstance(resp, dict) and resp.get("_timeout"): |
| 306 | return "TIMEOUT", f"{dt:.1f}s" |
| 307 | if "error" in resp: |
| 308 | err = resp["error"] |
| 309 | msg = err.get("message", "") if isinstance(err, dict) else str(err) |
| 310 | return "ERROR", msg[:100] |
| 311 | res = resp.get("result") |
| 312 | if res is None: |
| 313 | return "BAD", "no result" |
| 314 | if res.get("isError"): |
| 315 | c = res.get("content") or [{}] |
| 316 | return "ERROR", (c[0].get("text") or "")[:100] |
| 317 | c = res.get("content") |
| 318 | if not c: |
| 319 | return "EMPTY", "no content" |
| 320 | txt = c[0].get("text", "") |
| 321 | if not txt.strip(): |
| 322 | return "EMPTY", "blank" |
| 323 | if dt > 10: |
| 324 | return "SLOW", f"{dt:.1f}s" |
| 325 | return "OK", f"{dt:.2f}s" |
| 326 | |
| 327 | |
| 328 | # ---------------------------------------------------------------------------- main |
no outgoing calls
no test coverage detected