Skip to content

Commit ee5ebc1

Browse files
committed
not all errors are authentication errors. handling also general exception
1 parent 97be1f8 commit ee5ebc1

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

alpaca_trade_api/stream2.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,16 @@ 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+
elif msg.get('data', {}).get('error'):
50+
raise Exception(f"Error while connecting to {self._endpoint}:"
51+
f"{msg.get('data').get('error')}")
4752
else:
4853
self._retries = 0
4954

0 commit comments

Comments
 (0)