[GITEA] Handle non-existant commit in Archive request

- When a user requests a archive of a non-existant commit
`git.ErrNotExist` is returned, but was not gracefully handled resulting
in a 500 error.
- Doesn't exist in v1.22 due to it being refactored away in
cbf923e87b
- Adds integration test.
This commit is contained in:
Gusted 2024-01-04 23:09:07 +01:00
parent 95dcc2dd8c
commit 0fbf761d19
No known key found for this signature in database
GPG key ID: FD821B732837125F
2 changed files with 10 additions and 1 deletions

View file

@ -421,7 +421,7 @@ func Download(ctx *context.Context) {
if err != nil {
if errors.Is(err, archiver_service.ErrUnknownArchiveFormat{}) {
ctx.Error(http.StatusBadRequest, err.Error())
} else if errors.Is(err, archiver_service.RepoRefNotFoundError{}) {
} else if errors.Is(err, archiver_service.RepoRefNotFoundError{}) || git.IsErrNotExist(err) {
ctx.Error(http.StatusNotFound, err.Error())
} else {
ctx.ServerError("archiver_service.NewRequest", err)

View file

@ -720,3 +720,12 @@ func TestRenamedFileHistory(t *testing.T) {
htmlDoc.AssertElement(t, ".ui.bottom.attached.header", false)
})
}
func TestArchiveRequest(t *testing.T) {
defer tests.PrepareTestEnv(t)()
session := loginUser(t, "user2")
req := NewRequest(t, "GET", "/user2/repo1/archive/a480fe666d6f550787b6cc85047b966d1f8d6bbf.zip")
session.MakeRequest(t, req, http.StatusNotFound)
}