Closed mw66 closed 2 years ago
Also on line 204:
req.json()
basically every time we return json, we need to check if the req.text is empty first; otherwise, we have this error.
Something like this and if req.text is ""
it would just return that?
if resp_format == "json" and req.text != ""
...
I can see how a order list could come back blank but not sure we would expect similar responses elsewhere and have that be valid?
if it's empty, just return valid empty json object {}
.
otherwise, return regular json.
at that its probably best to handle the exception and on exception return {}
try:
req.json()
except simplejson.errors.JSONDecodeError:
return {}
What do you think?
Catching exception may hide other (unknown) errors, which should be avoided in general.
Right now etrade's response can only be either valid json object or empty (BTW, in this case they should return {}
from their server, but we cannot change their server behavior), so checking empty is good enough for this client library.
Shouldn't we have a final exception catch that does a raise so we can discover new etrade "features"?
when response is empty text
https://github.com/jessecooper/pyetrade/blob/master/pyetrade/order.py#L107
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)