Skip to content

Add flag to include the cause in the exception str #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions openai/error.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import openai
import os

display_cause = os.environ["OPENAI_ERROR_DISPLAY_CAUSE"]


class OpenAIError(Exception):
Expand Down Expand Up @@ -34,6 +37,8 @@ def __init__(

def __str__(self):
msg = self._message or "<empty message>"
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:
Expand Down