From 944029fdcc0966d7107d24159744c761a11dc0b3 Mon Sep 17 00:00:00 2001 From: Greg Brockman Date: Thu, 10 Nov 2022 13:58:01 -0800 Subject: [PATCH] Add environment variable to include the cause in exception str --- openai/error.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/openai/error.py b/openai/error.py index d22e71c902..4d74b8460e 100644 --- a/openai/error.py +++ b/openai/error.py @@ -1,4 +1,7 @@ import openai +import os + +display_cause = os.environ["OPENAI_ERROR_DISPLAY_CAUSE"] class OpenAIError(Exception): @@ -34,6 +37,8 @@ def __init__( def __str__(self): msg = self._message or "" + if display_cause is not None and hasattr(self, "__cause__") and self.__cause__ is not None: + msg += " (Cause: {0})".format(self.__cause__) if self.request_id is not None: return "Request {0}: {1}".format(self.request_id, msg) else: