Improve errorhandling on webserver endpoint
Part of https://github.com/freqtrade/frequi/issues/1387
This commit is contained in:
@@ -269,7 +269,10 @@ def pair_history(pair: str, timeframe: str, timerange: str, strategy: str,
|
|||||||
'timerange': timerange,
|
'timerange': timerange,
|
||||||
'freqaimodel': freqaimodel if freqaimodel else config.get('freqaimodel'),
|
'freqaimodel': freqaimodel if freqaimodel else config.get('freqaimodel'),
|
||||||
})
|
})
|
||||||
return RPC._rpc_analysed_history_full(config, pair, timeframe, exchange)
|
try:
|
||||||
|
return RPC._rpc_analysed_history_full(config, pair, timeframe, exchange)
|
||||||
|
except Exception as e:
|
||||||
|
raise HTTPException(status_code=502, detail=str(e))
|
||||||
|
|
||||||
|
|
||||||
@router.get('/plot_config', response_model=PlotConfig, tags=['candle data'])
|
@router.get('/plot_config', response_model=PlotConfig, tags=['candle data'])
|
||||||
@@ -284,7 +287,10 @@ def plot_config(strategy: Optional[str] = None, config=Depends(get_config),
|
|||||||
config1.update({
|
config1.update({
|
||||||
'strategy': strategy
|
'strategy': strategy
|
||||||
})
|
})
|
||||||
|
try:
|
||||||
return PlotConfig.parse_obj(RPC._rpc_plot_config_with_strategy(config1))
|
return PlotConfig.parse_obj(RPC._rpc_plot_config_with_strategy(config1))
|
||||||
|
except Exception as e:
|
||||||
|
raise HTTPException(status_code=502, detail=str(e))
|
||||||
|
|
||||||
|
|
||||||
@router.get('/strategies', response_model=StrategyListResponse, tags=['strategy'])
|
@router.get('/strategies', response_model=StrategyListResponse, tags=['strategy'])
|
||||||
|
|||||||
@@ -1476,6 +1476,12 @@ def test_api_pair_history(botclient, mocker):
|
|||||||
"&timerange=20180111-20180112")
|
"&timerange=20180111-20180112")
|
||||||
assert_response(rc, 422)
|
assert_response(rc, 422)
|
||||||
|
|
||||||
|
# Invalid strategy
|
||||||
|
rc = client_get(client,
|
||||||
|
f"{BASE_URI}/pair_history?pair=UNITTEST%2FBTC&timeframe={timeframe}"
|
||||||
|
"&timerange=20180111-20180112&strategy={CURRENT_TEST_STRATEGY}11")
|
||||||
|
assert_response(rc, 502)
|
||||||
|
|
||||||
# Working
|
# Working
|
||||||
rc = client_get(client,
|
rc = client_get(client,
|
||||||
f"{BASE_URI}/pair_history?pair=UNITTEST%2FBTC&timeframe={timeframe}"
|
f"{BASE_URI}/pair_history?pair=UNITTEST%2FBTC&timeframe={timeframe}"
|
||||||
@@ -1510,8 +1516,7 @@ def test_api_pair_history(botclient, mocker):
|
|||||||
f"{BASE_URI}/pair_history?pair=UNITTEST%2FBTC&timeframe={timeframe}"
|
f"{BASE_URI}/pair_history?pair=UNITTEST%2FBTC&timeframe={timeframe}"
|
||||||
f"&timerange=20200111-20200112&strategy={CURRENT_TEST_STRATEGY}")
|
f"&timerange=20200111-20200112&strategy={CURRENT_TEST_STRATEGY}")
|
||||||
assert_response(rc, 502)
|
assert_response(rc, 502)
|
||||||
assert rc.json()['error'] == ("Error querying /api/v1/pair_history: "
|
assert rc.json()['detail'] == ("No data for UNITTEST/BTC, 5m in 20200111-20200112 found.")
|
||||||
"No data for UNITTEST/BTC, 5m in 20200111-20200112 found.")
|
|
||||||
|
|
||||||
|
|
||||||
def test_api_plot_config(botclient, mocker):
|
def test_api_plot_config(botclient, mocker):
|
||||||
@@ -1548,6 +1553,10 @@ def test_api_plot_config(botclient, mocker):
|
|||||||
assert_response(rc)
|
assert_response(rc)
|
||||||
assert rc.json()['subplots'] == {}
|
assert rc.json()['subplots'] == {}
|
||||||
|
|
||||||
|
rc = client_get(client, f"{BASE_URI}/plot_config?strategy=NotAStrategy")
|
||||||
|
assert_response(rc, 502)
|
||||||
|
assert rc.json()['detail'] is not None
|
||||||
|
|
||||||
mocker.patch('freqtrade.rpc.api_server.api_v1.get_rpc_optional', return_value=None)
|
mocker.patch('freqtrade.rpc.api_server.api_v1.get_rpc_optional', return_value=None)
|
||||||
|
|
||||||
rc = client_get(client, f"{BASE_URI}/plot_config")
|
rc = client_get(client, f"{BASE_URI}/plot_config")
|
||||||
|
|||||||
Reference in New Issue
Block a user