Skip to content

Commit e9dfafb

Browse files
author
Shlomi Kushchi
authored
Merge pull request #196 from shlomikushchi/rc4_better_exception
Not all errors are authentication errors.
2 parents 1566c42 + a2187ed commit e9dfafb

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

alpaca_trade_api/stream2.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,18 @@ async def _connect(self):
3939
r = r.decode('utf-8')
4040
msg = json.loads(r)
4141

42-
if msg.get('data', {}).get('status') != 'authorized':
43-
raise ValueError(
44-
("Invalid Alpaca API credentials, Failed to authenticate: {}"
45-
.format(msg))
46-
)
42+
if msg.get('data', {}).get('status'):
43+
status = msg.get('data').get('status')
44+
if status != 'authorized':
45+
raise ValueError(
46+
(f"Invalid Alpaca API credentials, Failed to "
47+
f"authenticate: {msg}")
48+
)
49+
else:
50+
self._retries = 0
51+
elif msg.get('data', {}).get('error'):
52+
raise Exception(f"Error while connecting to {self._endpoint}:"
53+
f"{msg.get('data').get('error')}")
4754
else:
4855
self._retries = 0
4956

0 commit comments

Comments
 (0)