mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-13 12:16:29 +00:00
Backup not found returns 404 instead of 400 (#5479)
This commit is contained in:
parent
045454b597
commit
774aef74e8
@ -46,7 +46,7 @@ from ..const import (
|
||||
CoreState,
|
||||
)
|
||||
from ..coresys import CoreSysAttributes
|
||||
from ..exceptions import APIError, APIForbidden
|
||||
from ..exceptions import APIError, APIForbidden, APINotFound
|
||||
from ..jobs import JobSchedulerOptions
|
||||
from ..mounts.const import MountUsage
|
||||
from ..resolution.const import UnhealthyReason
|
||||
@ -134,7 +134,7 @@ class APIBackups(CoreSysAttributes):
|
||||
"""Return backup, throw an exception if it doesn't exist."""
|
||||
backup = self.sys_backups.get(request.match_info.get("slug"))
|
||||
if not backup:
|
||||
raise APIError("Backup does not exist")
|
||||
raise APINotFound("Backup does not exist")
|
||||
return backup
|
||||
|
||||
def _list_backups(self):
|
||||
|
@ -336,6 +336,12 @@ class APIForbidden(APIError):
|
||||
status = 403
|
||||
|
||||
|
||||
class APINotFound(APIError):
|
||||
"""API not found error."""
|
||||
|
||||
status = 404
|
||||
|
||||
|
||||
class APIAddonNotInstalled(APIError):
|
||||
"""Not installed addon requested at addons API."""
|
||||
|
||||
|
@ -729,3 +729,21 @@ async def test_upload_duplicate_backup_new_location(
|
||||
".cloud_backup": copy_backup,
|
||||
}
|
||||
assert coresys.backups.get("7fed74c8").location is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("method", "url"),
|
||||
[
|
||||
("get", "/backups/bad/info"),
|
||||
("delete", "/backups/bad"),
|
||||
("post", "/backups/bad/restore/full"),
|
||||
("post", "/backups/bad/restore/partial"),
|
||||
("get", "/backups/bad/download"),
|
||||
],
|
||||
)
|
||||
async def test_backup_not_found(api_client: TestClient, method: str, url: str):
|
||||
"""Test backup not found error."""
|
||||
resp = await api_client.request(method, url)
|
||||
assert resp.status == 404
|
||||
resp = await resp.json()
|
||||
assert resp["message"] == "Backup does not exist"
|
||||
|
Loading…
x
Reference in New Issue
Block a user