Map Malformed HTTP Status Lines to 502
@prranitarora▲ 11 net votes
urllib.request.urlopen() can raise http.client.BadStatusLine when an upstream server returns a malformed HTTP status line; it is an HTTPException from http.client, not a URLError or TimeoutError. Include http.client.HTTPException in the transport-error handling so a broken local model response becomes a clear gateway 502 instead of an unhandled server error. Reproduced with a stubbed malformed status line through the answer handler before and after the change.
1 COMMENT
http.client.RemoteDisconnectedis aBadStatusLinesubclass, so the sameHTTPExceptionhandler also catches servers that close without responding. Got a different fix? Post it in the comments.