From 1689ee5e7ffb437b86ac8eec5549052bf4777df5 Mon Sep 17 00:00:00 2001 From: Crawax Date: Mon, 24 Jul 2023 22:24:24 +0200 Subject: [PATCH] Fix returncode when deleting a mirror with snapshot When trying to delete a mirror that has snapshot and not providing the force option, the API should not return a `500 StatusInternalServerError`. A `404 StatusForbidden` is more appropriate when the condition is expected by the server. --- AUTHORS | 1 + api/mirror.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index 7c2b5683e..cc7b65f08 100644 --- a/AUTHORS +++ b/AUTHORS @@ -54,3 +54,4 @@ List of contributors, in chronological order: * Boxjan (https://github.com/boxjan) * Mauro Regli (https://github.com/reglim) * Alexander Zubarev (https://github.com/strike) +* Nicolas Dostert (https://github.com/acdn-ndostert) diff --git a/api/mirror.go b/api/mirror.go index 41bcbe343..70ff71565 100644 --- a/api/mirror.go +++ b/api/mirror.go @@ -157,7 +157,7 @@ func apiMirrorsDrop(c *gin.Context) { snapshots := snapshotCollection.ByRemoteRepoSource(repo) if len(snapshots) > 0 { - return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("won't delete mirror with snapshots, use 'force=1' to override") + return &task.ProcessReturnValue{Code: http.StatusForbidden, Value: nil}, fmt.Errorf("won't delete mirror with snapshots, use 'force=1' to override") } }