mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-08 17:56:33 +00:00
APIForbidden should result in 403 status (#4943)
This commit is contained in:
parent
bb5e138134
commit
2c7b417e25
@ -129,12 +129,15 @@ def api_return_error(
|
|||||||
JSON_RESULT: RESULT_ERROR,
|
JSON_RESULT: RESULT_ERROR,
|
||||||
JSON_MESSAGE: message or "Unknown error, see supervisor",
|
JSON_MESSAGE: message or "Unknown error, see supervisor",
|
||||||
}
|
}
|
||||||
if isinstance(error, APIError) and error.job_id:
|
status = 400
|
||||||
|
if isinstance(error, APIError):
|
||||||
|
status = error.status
|
||||||
|
if error.job_id:
|
||||||
result[JSON_JOB_ID] = error.job_id
|
result[JSON_JOB_ID] = error.job_id
|
||||||
|
|
||||||
return web.json_response(
|
return web.json_response(
|
||||||
result,
|
result,
|
||||||
status=400,
|
status=status,
|
||||||
dumps=json_dumps,
|
dumps=json_dumps,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -308,6 +308,8 @@ class HostLogError(HostError):
|
|||||||
class APIError(HassioError, RuntimeError):
|
class APIError(HassioError, RuntimeError):
|
||||||
"""API errors."""
|
"""API errors."""
|
||||||
|
|
||||||
|
status = 400
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
message: str | None = None,
|
message: str | None = None,
|
||||||
@ -322,6 +324,8 @@ class APIError(HassioError, RuntimeError):
|
|||||||
class APIForbidden(APIError):
|
class APIForbidden(APIError):
|
||||||
"""API forbidden error."""
|
"""API forbidden error."""
|
||||||
|
|
||||||
|
status = 403
|
||||||
|
|
||||||
|
|
||||||
class APIAddonNotInstalled(APIError):
|
class APIAddonNotInstalled(APIError):
|
||||||
"""Not installed addon requested at addons API."""
|
"""Not installed addon requested at addons API."""
|
||||||
|
@ -25,7 +25,7 @@ async def test_api_discovery_forbidden(
|
|||||||
with caplog.at_level(logging.ERROR):
|
with caplog.at_level(logging.ERROR):
|
||||||
resp = await api_client.post("/discovery", json={"service": "mqtt"})
|
resp = await api_client.post("/discovery", json={"service": "mqtt"})
|
||||||
|
|
||||||
assert resp.status == 400
|
assert resp.status == 403
|
||||||
result = await resp.json()
|
result = await resp.json()
|
||||||
assert result["result"] == "error"
|
assert result["result"] == "error"
|
||||||
assert (
|
assert (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user