mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-03-12 22:51:44 -05:00
feat: improve error handling of commit rendering
- Simplify if-else expression to `NotFoundOrServerError`. - I cannot find an existing scenario where `Getdiff` returns an error and where it therefore should show a 404 error in the context of rendering a diff of a commit. So simply return it as an Internal Server Error, this also helps with debugging if an actual error occurs here (404 errors are only logged at the DEBUG level). - The first change is already covered under existing testing, the second change is not trivial to test.
This commit is contained in:
parent
c1399947f4
commit
4c123d8e3b
1 changed files with 2 additions and 6 deletions
|
@ -315,11 +315,7 @@ func Diff(ctx *context.Context) {
|
||||||
|
|
||||||
commit, err := gitRepo.GetCommit(commitID)
|
commit, err := gitRepo.GetCommit(commitID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if git.IsErrNotExist(err) {
|
ctx.NotFoundOrServerError("gitRepo.GetCommit", git.IsErrNotExist, err)
|
||||||
ctx.NotFound("Repo.GitRepo.GetCommit", err)
|
|
||||||
} else {
|
|
||||||
ctx.ServerError("Repo.GitRepo.GetCommit", err)
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(commitID) != commit.ID.Type().FullLength() {
|
if len(commitID) != commit.ID.Type().FullLength() {
|
||||||
|
@ -343,7 +339,7 @@ func Diff(ctx *context.Context) {
|
||||||
FileOnly: fileOnly,
|
FileOnly: fileOnly,
|
||||||
}, files...)
|
}, files...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.NotFound("GetDiff", err)
|
ctx.ServerError("GetDiff", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue