Commit 9678e154

Greg Brockman <gdb@gregbrockman.com>
2023-01-07 04:19:38
Including the underlying errors in the error message for Timeout & APIConnectionError (#137)
Many libraries will only show the error string of the raised error, not displaying its cause. Prior to this path, this would mean that the many different kinds of connection errors get translated into a single opaque "Error communicating with OpenAI".
1 parent 7af43ce
Changed files (1)
openai/api_requestor.py
@@ -505,9 +505,9 @@ class APIRequestor:
                 timeout=request_timeout if request_timeout else TIMEOUT_SECS,
             )
         except requests.exceptions.Timeout as e:
-            raise error.Timeout("Request timed out") from e
+            raise error.Timeout("Request timed out: {}".format(e)) from e
         except requests.exceptions.RequestException as e:
-            raise error.APIConnectionError("Error communicating with OpenAI") from e
+            raise error.APIConnectionError("Error communicating with OpenAI: {}".format(e)) from e
         util.log_info(
             "OpenAI API response",
             path=abs_url,