From e4f7307511326b92b1277a56441df33f567ddc94 Mon Sep 17 00:00:00 2001 From: Kemal Zebari Date: Sun, 17 Nov 2024 21:34:07 -0800 Subject: [PATCH] Keep "non-existent branch" HTTP responses consistent --- routers/api/v1/repo/branch.go | 4 ++-- tests/integration/api_branch_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/routers/api/v1/repo/branch.go b/routers/api/v1/repo/branch.go index a17f0ad40d..62cebaec62 100644 --- a/routers/api/v1/repo/branch.go +++ b/routers/api/v1/repo/branch.go @@ -462,7 +462,7 @@ func UpdateBranch(ctx *context.APIContext) { return } if msg == "from_not_exist" { - ctx.Error(http.StatusUnprocessableEntity, "", "Branch doesn't exist.") + ctx.Error(http.StatusNotFound, "", "Branch doesn't exist.") return } } else { @@ -474,7 +474,7 @@ func UpdateBranch(ctx *context.APIContext) { if git.IsErrBranchNotExist(err) { // This could occur if the client passes a non-existent branch and we // skip executing the branch that contains the RenameBranch() call. - ctx.NotFound(err) + ctx.Error(http.StatusNotFound, "", "Branch doesn't exist.") return } ctx.Error(http.StatusInternalServerError, "GetBranch", err) diff --git a/tests/integration/api_branch_test.go b/tests/integration/api_branch_test.go index e2b3dc86fb..a2b71dcf24 100644 --- a/tests/integration/api_branch_test.go +++ b/tests/integration/api_branch_test.go @@ -201,7 +201,7 @@ func TestAPIUpdateBranch(t *testing.T) { assert.Contains(t, resp.Body.String(), "Cannot rename a branch using the same name or rename to a branch that already exists.") }) t.Run("UpdateBranchWithNonExistentBranch", func(t *testing.T) { - resp := testAPIUpdateBranch(t, "user2", "repo1", "i-dont-exist", "new-branch-name", http.StatusUnprocessableEntity) + resp := testAPIUpdateBranch(t, "user2", "repo1", "i-dont-exist", "new-branch-name", http.StatusNotFound) assert.Contains(t, resp.Body.String(), "Branch doesn't exist.") }) t.Run("UpdateBranchWithEmptyStringAsNewName", func(t *testing.T) {