Skip to content

Commit e4f7307

Browse files
committed
Keep "non-existent branch" HTTP responses consistent
1 parent 1ad8de7 commit e4f7307

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

routers/api/v1/repo/branch.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ func UpdateBranch(ctx *context.APIContext) {
462462
return
463463
}
464464
if msg == "from_not_exist" {
465-
ctx.Error(http.StatusUnprocessableEntity, "", "Branch doesn't exist.")
465+
ctx.Error(http.StatusNotFound, "", "Branch doesn't exist.")
466466
return
467467
}
468468
} else {
@@ -474,7 +474,7 @@ func UpdateBranch(ctx *context.APIContext) {
474474
if git.IsErrBranchNotExist(err) {
475475
// This could occur if the client passes a non-existent branch and we
476476
// skip executing the branch that contains the RenameBranch() call.
477-
ctx.NotFound(err)
477+
ctx.Error(http.StatusNotFound, "", "Branch doesn't exist.")
478478
return
479479
}
480480
ctx.Error(http.StatusInternalServerError, "GetBranch", err)

tests/integration/api_branch_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func TestAPIUpdateBranch(t *testing.T) {
201201
assert.Contains(t, resp.Body.String(), "Cannot rename a branch using the same name or rename to a branch that already exists.")
202202
})
203203
t.Run("UpdateBranchWithNonExistentBranch", func(t *testing.T) {
204-
resp := testAPIUpdateBranch(t, "user2", "repo1", "i-dont-exist", "new-branch-name", http.StatusUnprocessableEntity)
204+
resp := testAPIUpdateBranch(t, "user2", "repo1", "i-dont-exist", "new-branch-name", http.StatusNotFound)
205205
assert.Contains(t, resp.Body.String(), "Branch doesn't exist.")
206206
})
207207
t.Run("UpdateBranchWithEmptyStringAsNewName", func(t *testing.T) {

0 commit comments

Comments
 (0)