Skip to content

Commit 6a82204

Browse files
committed
Keep "non-existent branch" HTTP responses consistent
1 parent 6d221ed commit 6a82204

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
@@ -452,7 +452,7 @@ func UpdateBranch(ctx *context.APIContext) {
452452
return
453453
}
454454
if msg == "from_not_exist" {
455-
ctx.Error(http.StatusUnprocessableEntity, "", "Branch doesn't exist.")
455+
ctx.Error(http.StatusNotFound, "", "Branch doesn't exist.")
456456
return
457457
}
458458
} else {
@@ -464,7 +464,7 @@ func UpdateBranch(ctx *context.APIContext) {
464464
if git.IsErrBranchNotExist(err) {
465465
// This could occur if the client passes a non-existent branch and we
466466
// skip executing the branch that contains the RenameBranch() call.
467-
ctx.NotFound(err)
467+
ctx.Error(http.StatusNotFound, "", "Branch doesn't exist.")
468468
return
469469
}
470470
ctx.Error(http.StatusInternalServerError, "GetBranch", err)

tests/integration/api_branch_test.go

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

0 commit comments

Comments
 (0)