(response: Response, *, streaming: bool)
| 5252 | )) |
| 5253 | |
| 5254 | def _record_response_error(response: Response, *, streaming: bool) -> None: |
| 5255 | body = getattr(response, "body", b"") or b"" |
| 5256 | if not isinstance(body, (bytes, bytearray)): |
| 5257 | body = bytes(body) |
| 5258 | derived_error_code, derived_error_message = _extract_error_details(response.status_code, body) |
| 5259 | if derived_error_code == "spend_limit_exceeded": |
| 5260 | error_stage_value = "guardrail" |
| 5261 | else: |
| 5262 | error_stage_value = "upstream_response" |
| 5263 | _record_route_trace( |
| 5264 | status_code=response.status_code, |
| 5265 | streaming=streaming, |
| 5266 | error_code=derived_error_code, |
| 5267 | error_stage=error_stage_value, |
| 5268 | error_message=derived_error_message, |
| 5269 | ) |
| 5270 | |
| 5271 | # Tracks whether the streaming path has completed a record() call. |
| 5272 | # Needed because Starlette cancels the response generator when the |
no test coverage detected