Skip to content

Commit 5c5f102

Browse files
committed
fix: don't 500 on strange version for revision API
Signed-off-by: Paul Spooren <mail@aparcar.org>
1 parent 4b33241 commit 5c5f102

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

asu/routers/api.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ def api_v1_revision(
3838
version: str, target: str, subtarget: str, response: Response, request: Request
3939
):
4040
branch_data = get_branch(version)
41+
if "path" not in branch_data:
42+
response.status_code = 400
43+
return {
44+
"detail": f"Unsupported version: {version}",
45+
"status": 400,
46+
}
4147
version_path = branch_data["path"].format(version=version)
4248
req = client_get(
4349
settings.upstream_url

tests/test_api.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,15 @@ def test_api_revision(client):
758758
assert data["revision"] == "r24106-10cc5fcd00"
759759

760760

761+
def test_api_revision_bad_version(client):
762+
response = client.get(
763+
"/api/v1/revision/invalid-version/ath79/generic", follow_redirects=False
764+
)
765+
assert response.status_code == 400
766+
data = response.json()
767+
assert data["detail"] == "Unsupported version: invalid-version"
768+
769+
761770
def test_api_stats(client):
762771
response = client.get("/api/v1/stats", follow_redirects=False)
763772
assert response.status_code == 200

0 commit comments

Comments
 (0)