fix(api): use not found status code when appropriate (#6885)

- Use a 404 error when the issue not found instead of returning an internal server error.
- Resolves #4005
- Added integration test.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6885
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: ThomasBoom89 <thomasboom89@noreply.codeberg.org>
Co-committed-by: ThomasBoom89 <thomasboom89@noreply.codeberg.org>
This commit is contained in:
ThomasBoom89 2025-02-12 20:18:33 +00:00 committed by Gusted
parent ab69057327
commit 5feca875ea
4 changed files with 119 additions and 8 deletions

View file

@ -157,6 +157,17 @@ type swaggerAPIRepoArchivedError struct {
Body APIRepoArchivedError `json:"body"`
}
type APIInternalServerError struct {
APIError
}
// APIInternalServerError is an error that is raised when an internal server error occurs
// swagger:response internalServerError
type swaggerAPIInternalServerError struct {
// in:body
Body APIInternalServerError `json:"body"`
}
// ServerError responds with error message, status is 500
func (ctx *APIContext) ServerError(title string, err error) {
ctx.Error(http.StatusInternalServerError, title, err)