Commit 7ea5dde9

Max Schaefer <54907921+max-schaefer@users.noreply.github.com>
2022-01-20 06:24:27
Fix recording of reponse headers in exceptions. (#44)
These were passed as positional arguments, but in the wrong position, which meant they were passed into the `json_body` parameter of the `OpenAIError` constructor.
1 parent 25b681a
Changed files (1)
openai/api_requestor.py
@@ -300,7 +300,7 @@ class APIRequestor:
     ) -> OpenAIResponse:
         if rcode == 503:
             raise error.ServiceUnavailableError(
-                "The server is overloaded or not ready yet.", rbody, rcode, rheaders
+                "The server is overloaded or not ready yet.", rbody, rcode, headers=rheaders
             )
         try:
             if hasattr(rbody, "decode"):
@@ -308,7 +308,7 @@ class APIRequestor:
             data = json.loads(rbody)
         except (JSONDecodeError, UnicodeDecodeError):
             raise error.APIError(
-                f"HTTP code {rcode} from API ({rbody})", rbody, rcode, rheaders
+                f"HTTP code {rcode} from API ({rbody})", rbody, rcode, headers=rheaders
             )
         resp = OpenAIResponse(data, rheaders)
         # In the future, we might add a "status" parameter to errors