Skip to content

Commit 774aef7

Browse files
authored
Backup not found returns 404 instead of 400 (#5479)
1 parent 045454b commit 774aef7

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

supervisor/api/backups.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
CoreState,
4747
)
4848
from ..coresys import CoreSysAttributes
49-
from ..exceptions import APIError, APIForbidden
49+
from ..exceptions import APIError, APIForbidden, APINotFound
5050
from ..jobs import JobSchedulerOptions
5151
from ..mounts.const import MountUsage
5252
from ..resolution.const import UnhealthyReason
@@ -134,7 +134,7 @@ def _extract_slug(self, request):
134134
"""Return backup, throw an exception if it doesn't exist."""
135135
backup = self.sys_backups.get(request.match_info.get("slug"))
136136
if not backup:
137-
raise APIError("Backup does not exist")
137+
raise APINotFound("Backup does not exist")
138138
return backup
139139

140140
def _list_backups(self):

supervisor/exceptions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,12 @@ class APIForbidden(APIError):
336336
status = 403
337337

338338

339+
class APINotFound(APIError):
340+
"""API not found error."""
341+
342+
status = 404
343+
344+
339345
class APIAddonNotInstalled(APIError):
340346
"""Not installed addon requested at addons API."""
341347

tests/api/test_backups.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,3 +729,21 @@ async def test_upload_duplicate_backup_new_location(
729729
".cloud_backup": copy_backup,
730730
}
731731
assert coresys.backups.get("7fed74c8").location is None
732+
733+
734+
@pytest.mark.parametrize(
735+
("method", "url"),
736+
[
737+
("get", "/backups/bad/info"),
738+
("delete", "/backups/bad"),
739+
("post", "/backups/bad/restore/full"),
740+
("post", "/backups/bad/restore/partial"),
741+
("get", "/backups/bad/download"),
742+
],
743+
)
744+
async def test_backup_not_found(api_client: TestClient, method: str, url: str):
745+
"""Test backup not found error."""
746+
resp = await api_client.request(method, url)
747+
assert resp.status == 404
748+
resp = await resp.json()
749+
assert resp["message"] == "Backup does not exist"

0 commit comments

Comments
 (0)