Raise correct httperrorcode for webserver-only endpoitns

This commit is contained in:
Matthias
2023-06-01 07:03:07 +02:00
parent 9c6fee3841
commit e0d9603e99
2 changed files with 8 additions and 4 deletions
+3 -2
View File
@@ -1,7 +1,7 @@
from typing import Any, AsyncIterator, Dict, Optional from typing import Any, AsyncIterator, Dict, Optional
from uuid import uuid4 from uuid import uuid4
from fastapi import Depends from fastapi import Depends, HTTPException
from freqtrade.enums import RunMode from freqtrade.enums import RunMode
from freqtrade.persistence import Trade from freqtrade.persistence import Trade
@@ -57,5 +57,6 @@ def get_message_stream():
def is_webserver_mode(config=Depends(get_config)): def is_webserver_mode(config=Depends(get_config)):
if config['runmode'] != RunMode.WEBSERVER: if config['runmode'] != RunMode.WEBSERVER:
raise RPCException('Bot is not in the correct state') raise HTTPException(status_code=503,
detail='Bot is not in the correct state.')
return None return None
+5 -2
View File
@@ -1673,7 +1673,8 @@ def test_api_backtesting(botclient, mocker, fee, caplog, tmpdir):
rc = client_get(client, f"{BASE_URI}/backtest") rc = client_get(client, f"{BASE_URI}/backtest")
# Backtest prevented in default mode # Backtest prevented in default mode
assert_response(rc, 502) assert_response(rc, 503)
assert rc.json()['detail'] == 'Bot is not in the correct state.'
ftbot.config['runmode'] = RunMode.WEBSERVER ftbot.config['runmode'] = RunMode.WEBSERVER
# Backtesting not started yet # Backtesting not started yet
@@ -1812,7 +1813,9 @@ def test_api_backtest_history(botclient, mocker, testdatadir):
]) ])
rc = client_get(client, f"{BASE_URI}/backtest/history") rc = client_get(client, f"{BASE_URI}/backtest/history")
assert_response(rc, 502) assert_response(rc, 503)
assert rc.json()['detail'] == 'Bot is not in the correct state.'
ftbot.config['user_data_dir'] = testdatadir ftbot.config['user_data_dir'] = testdatadir
ftbot.config['runmode'] = RunMode.WEBSERVER ftbot.config['runmode'] = RunMode.WEBSERVER