MCPcopy
hub / github.com/HisMax/RedInk / _extract_status_and_message

Function _extract_status_and_message

backend/errors.py:273–304  ·  view source on GitHub ↗
(raw: str)

Source from the content-addressed store, hash-verified

271
272
273def _extract_status_and_message(raw: str) -> Tuple[Optional[int], Optional[str]]:
274 status = None
275 status_match = re.search(r"(?:HTTP|状态码[::]?)\s*[::]?\s*(\d{3})", raw, re.IGNORECASE)
276 if status_match:
277 status = int(status_match.group(1))
278 else:
279 leading_status_match = re.search(r"^\s*(\d{3})\s+[A-Za-z]", raw)
280 if leading_status_match:
281 status = int(leading_status_match.group(1))
282
283 json_match = re.search(r"(\{.*\})", raw, re.DOTALL)
284 if json_match:
285 try:
286 payload = json.loads(json_match.group(1))
287 error = payload.get("error") if isinstance(payload, dict) else None
288 if isinstance(error, dict):
289 message = error.get("message") or error.get("detail")
290 if message:
291 return status, str(message)
292 if isinstance(error, str):
293 return status, error
294 except Exception:
295 pass
296
297 original_match = re.search(r"【原始错误】\s*([\s\S]+)", raw)
298 if original_match:
299 return status, _first_meaningful_line(original_match.group(1))
300
301 if "<html" in raw.lower() or "<!doctype" in raw.lower():
302 return status, _summarize_html(raw)
303
304 return status, None
305
306
307def _extract_host(raw: str) -> Optional[str]:

Callers 1

classify_errorFunction · 0.85

Calls 3

_first_meaningful_lineFunction · 0.85
_summarize_htmlFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected