Skip to content
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

feat: detailed error elated to API key and environment mismatch #391

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
19 changes: 18 additions & 1 deletion alpaca/common/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,26 @@ class APIError(Exception):
"""

def __init__(self, error, http_error=None):
super().__init__(error)
detailed_error = {
"payload": error,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, please let me re-consider about compatibility with previous message field.

}

if http_error is not None:
if hasattr(http_error, "response"):
detailed_error["status_code"] = http_error.response.status_code
detailed_error["reason"] = http_error.response.reason
if hasattr(http_error, "request"):
detailed_error["method"] = http_error.request.method
detailed_error["url"] = http_error.request.url
# add tips for auth key error
if detailed_error["status_code"] == 401:
detailed_error[
"tips"
] = "please check your API key and environment (paper/sandbox/live)"

self._error = error
self._http_error = http_error
super().__init__(detailed_error)

@property
def code(self):
Expand Down