Add message from Bad Request errors to HassioAPIError (#113144)
Co-authored-by: Mike Degatano <michael.degatano@gmail.com>
This commit is contained in:
parent
6ecafbcc2c
commit
99eaa07f6f
4 changed files with 47 additions and 10 deletions
|
@ -172,6 +172,7 @@ async def test_websocket_supervisor_api_error(
|
|||
aioclient_mock.get(
|
||||
"http://127.0.0.1/ping",
|
||||
json={"result": "error", "message": "example error"},
|
||||
status=400,
|
||||
)
|
||||
|
||||
await websocket_client.send_json(
|
||||
|
@ -184,9 +185,39 @@ async def test_websocket_supervisor_api_error(
|
|||
)
|
||||
|
||||
msg = await websocket_client.receive_json()
|
||||
assert msg["error"]["code"] == "unknown_error"
|
||||
assert msg["error"]["message"] == "example error"
|
||||
|
||||
|
||||
async def test_websocket_supervisor_api_error_without_msg(
|
||||
hassio_env,
|
||||
hass: HomeAssistant,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
aioclient_mock: AiohttpClientMocker,
|
||||
) -> None:
|
||||
"""Test Supervisor websocket api error."""
|
||||
assert await async_setup_component(hass, "hassio", {})
|
||||
websocket_client = await hass_ws_client(hass)
|
||||
aioclient_mock.get(
|
||||
"http://127.0.0.1/ping",
|
||||
json={},
|
||||
status=400,
|
||||
)
|
||||
|
||||
await websocket_client.send_json(
|
||||
{
|
||||
WS_ID: 1,
|
||||
WS_TYPE: WS_TYPE_API,
|
||||
ATTR_ENDPOINT: "/ping",
|
||||
ATTR_METHOD: "get",
|
||||
}
|
||||
)
|
||||
|
||||
msg = await websocket_client.receive_json()
|
||||
assert msg["error"]["code"] == "unknown_error"
|
||||
assert msg["error"]["message"] == ""
|
||||
|
||||
|
||||
async def test_websocket_non_admin_user(
|
||||
hassio_env,
|
||||
hass: HomeAssistant,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue