mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-18 04:12:00 +03:00
Backport #20886 Add code to test if GetAttachmentByID returns an ErrAttachmentNotExist error and return NotFound instead of InternalServerError Fix #20884 Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
parent
bc7a4375be
commit
5ebd26d306
1 changed files with 20 additions and 0 deletions
|
@ -57,6 +57,10 @@ func GetReleaseAttachment(ctx *context.APIContext) {
|
||||||
attachID := ctx.ParamsInt64(":asset")
|
attachID := ctx.ParamsInt64(":asset")
|
||||||
attach, err := repo_model.GetAttachmentByID(ctx, attachID)
|
attach, err := repo_model.GetAttachmentByID(ctx, attachID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if repo_model.IsErrAttachmentNotExist(err) {
|
||||||
|
ctx.NotFound()
|
||||||
|
return
|
||||||
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetAttachmentByID", err)
|
ctx.Error(http.StatusInternalServerError, "GetAttachmentByID", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -100,6 +104,10 @@ func ListReleaseAttachments(ctx *context.APIContext) {
|
||||||
releaseID := ctx.ParamsInt64(":id")
|
releaseID := ctx.ParamsInt64(":id")
|
||||||
release, err := models.GetReleaseByID(ctx, releaseID)
|
release, err := models.GetReleaseByID(ctx, releaseID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if models.IsErrReleaseNotExist(err) {
|
||||||
|
ctx.NotFound()
|
||||||
|
return
|
||||||
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetReleaseByID", err)
|
ctx.Error(http.StatusInternalServerError, "GetReleaseByID", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -166,6 +174,10 @@ func CreateReleaseAttachment(ctx *context.APIContext) {
|
||||||
releaseID := ctx.ParamsInt64(":id")
|
releaseID := ctx.ParamsInt64(":id")
|
||||||
release, err := models.GetReleaseByID(ctx, releaseID)
|
release, err := models.GetReleaseByID(ctx, releaseID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if models.IsErrReleaseNotExist(err) {
|
||||||
|
ctx.NotFound()
|
||||||
|
return
|
||||||
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetReleaseByID", err)
|
ctx.Error(http.StatusInternalServerError, "GetReleaseByID", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -244,6 +256,10 @@ func EditReleaseAttachment(ctx *context.APIContext) {
|
||||||
attachID := ctx.ParamsInt64(":asset")
|
attachID := ctx.ParamsInt64(":asset")
|
||||||
attach, err := repo_model.GetAttachmentByID(ctx, attachID)
|
attach, err := repo_model.GetAttachmentByID(ctx, attachID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if repo_model.IsErrAttachmentNotExist(err) {
|
||||||
|
ctx.NotFound()
|
||||||
|
return
|
||||||
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetAttachmentByID", err)
|
ctx.Error(http.StatusInternalServerError, "GetAttachmentByID", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -302,6 +318,10 @@ func DeleteReleaseAttachment(ctx *context.APIContext) {
|
||||||
attachID := ctx.ParamsInt64(":asset")
|
attachID := ctx.ParamsInt64(":asset")
|
||||||
attach, err := repo_model.GetAttachmentByID(ctx, attachID)
|
attach, err := repo_model.GetAttachmentByID(ctx, attachID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if repo_model.IsErrAttachmentNotExist(err) {
|
||||||
|
ctx.NotFound()
|
||||||
|
return
|
||||||
|
}
|
||||||
ctx.Error(http.StatusInternalServerError, "GetAttachmentByID", err)
|
ctx.Error(http.StatusInternalServerError, "GetAttachmentByID", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue