(20241224) Validation error catching.
This commit is contained in:
@@ -65,6 +65,9 @@ import httpx
|
||||
# To work with Zerodha's Kite platform:
|
||||
from kiteconnect import KiteConnect
|
||||
|
||||
# To handle exceptions:
|
||||
from pydantic import ValidationError
|
||||
|
||||
|
||||
# *****************************************************************************************************************
|
||||
# ***** ****
|
||||
@@ -265,11 +268,11 @@ class ZerodhaKiteTradingController(TradingController):
|
||||
# Start by assuming failure:
|
||||
symbol_list = TradingSymbolListBrokerResponse()
|
||||
|
||||
try:
|
||||
|
||||
# Fit the token into the model:
|
||||
zerodha_token = ZerodhaKiteAuthTokens(**auth_token.token)
|
||||
|
||||
try:
|
||||
|
||||
# Now create an instance of the Kite:
|
||||
kite = KiteConnect(api_key = auth_token.auth["apiKey"])
|
||||
kite.set_access_token(zerodha_token.accessToken)
|
||||
@@ -285,9 +288,11 @@ class ZerodhaKiteTradingController(TradingController):
|
||||
|
||||
# In case something goes wrong:
|
||||
except Exception as exception:
|
||||
symbol_list.exception = exception
|
||||
symbol_list.message = str(exception)
|
||||
symbol_list.data = None
|
||||
symbol_list.exception = exception
|
||||
if isinstance(exception, ValidationError):
|
||||
symbol_list.message = "Token error. Please log in to your Zerodha (Kite) account again."
|
||||
else: symbol_list.message = str(exception)
|
||||
|
||||
# Done here:
|
||||
return symbol_list
|
||||
|
||||
Reference in New Issue
Block a user