-
Notifications
You must be signed in to change notification settings - Fork 155
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
Enhances how the SDK handles API error messages #338
base: master
Are you sure you want to change the base?
Conversation
f99380b
to
a892752
Compare
68527b6
to
032a78b
Compare
alpaca/broker/client.py
Outdated
assert ( | ||
"id" in last_result | ||
), "AccountActivity didn't contain an `id` field to use for paginating results" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert
is ignored if optimization is requested. Therefore, if we need to handle an error, we should not use assert
as a error handling method.
ref. https://docs.python.org/3.12/reference/simple_stmts.html#the-assert-statement
alpaca/common/models.py
Outdated
@@ -1,4 +1,4 @@ | |||
from pydantic import BaseModel | |||
from pydantic import BaseModel, ConfigDict |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ConfigDict
could be removed?
bd30ba5
to
e3ad16e
Compare
alpaca/broker/client.py
Outdated
@@ -525,7 +525,7 @@ def _get_account_activities_iterator( | |||
last_result = result[-1] | |||
|
|||
if "id" not in last_result: | |||
raise APIError( | |||
raise AssertionError( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
built-in AssertionError
is defined as Raised when an assert statement fails.
.
Could be something different exception?
ref. https://docs.python.org/3/library/exceptions.html#AssertionError
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can raise ValueError
or AttributeError
? Which one it's better in your opinion? I'd go with the attribute error based on the docs
alpaca/broker/client.py
Outdated
# we got here either by error or someone has mis-configured us, so we didn't even try | ||
raise Exception("Somehow we never made a request for download!") | ||
# we got here either by error or someone has mis-configured us, so we didn't even try | ||
assert isinstance( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this assert also can be replaceable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd raise a TypeError here, sounds good?
No description provided.