aboutsummaryrefslogtreecommitdiffstats
path: root/routers/api/v1/repo/release_attachment.go
diff options
context:
space:
mode:
Diffstat (limited to 'routers/api/v1/repo/release_attachment.go')
-rw-r--r--routers/api/v1/repo/release_attachment.go48
1 files changed, 24 insertions, 24 deletions
diff --git a/routers/api/v1/repo/release_attachment.go b/routers/api/v1/repo/release_attachment.go
index 54ca1fc843..defde81a1d 100644
--- a/routers/api/v1/repo/release_attachment.go
+++ b/routers/api/v1/repo/release_attachment.go
@@ -23,14 +23,14 @@ func checkReleaseMatchRepo(ctx *context.APIContext, releaseID int64) bool {
release, err := repo_model.GetReleaseByID(ctx, releaseID)
if err != nil {
if repo_model.IsErrReleaseNotExist(err) {
- ctx.NotFound()
+ ctx.APIErrorNotFound()
return false
}
- ctx.Error(http.StatusInternalServerError, "GetReleaseByID", err)
+ ctx.APIErrorInternal(err)
return false
}
if release.RepoID != ctx.Repo.Repository.ID {
- ctx.NotFound()
+ ctx.APIErrorNotFound()
return false
}
return true
@@ -81,15 +81,15 @@ func GetReleaseAttachment(ctx *context.APIContext) {
attach, err := repo_model.GetAttachmentByID(ctx, attachID)
if err != nil {
if repo_model.IsErrAttachmentNotExist(err) {
- ctx.NotFound()
+ ctx.APIErrorNotFound()
return
}
- ctx.Error(http.StatusInternalServerError, "GetAttachmentByID", err)
+ ctx.APIErrorInternal(err)
return
}
if attach.ReleaseID != releaseID {
log.Info("User requested attachment is not in release, release_id %v, attachment_id: %v", releaseID, attachID)
- ctx.NotFound()
+ ctx.APIErrorNotFound()
return
}
// FIXME Should prove the existence of the given repo, but results in unnecessary database requests
@@ -130,18 +130,18 @@ func ListReleaseAttachments(ctx *context.APIContext) {
release, err := repo_model.GetReleaseByID(ctx, releaseID)
if err != nil {
if repo_model.IsErrReleaseNotExist(err) {
- ctx.NotFound()
+ ctx.APIErrorNotFound()
return
}
- ctx.Error(http.StatusInternalServerError, "GetReleaseByID", err)
+ ctx.APIErrorInternal(err)
return
}
if release.RepoID != ctx.Repo.Repository.ID {
- ctx.NotFound()
+ ctx.APIErrorNotFound()
return
}
if err := release.LoadAttributes(ctx); err != nil {
- ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
+ ctx.APIErrorInternal(err)
return
}
ctx.JSON(http.StatusOK, convert.ToAPIRelease(ctx, ctx.Repo.Repository, release).Attachments)
@@ -194,7 +194,7 @@ func CreateReleaseAttachment(ctx *context.APIContext) {
// Check if attachments are enabled
if !setting.Attachment.Enabled {
- ctx.NotFound("Attachment is not enabled")
+ ctx.APIErrorNotFound("Attachment is not enabled")
return
}
@@ -212,7 +212,7 @@ func CreateReleaseAttachment(ctx *context.APIContext) {
if strings.HasPrefix(strings.ToLower(ctx.Req.Header.Get("Content-Type")), "multipart/form-data") {
file, header, err := ctx.Req.FormFile("attachment")
if err != nil {
- ctx.Error(http.StatusInternalServerError, "GetFile", err)
+ ctx.APIErrorInternal(err)
return
}
defer file.Close()
@@ -229,7 +229,7 @@ func CreateReleaseAttachment(ctx *context.APIContext) {
}
if filename == "" {
- ctx.Error(http.StatusBadRequest, "CreateReleaseAttachment", "Could not determine name of attachment.")
+ ctx.APIError(http.StatusBadRequest, "Could not determine name of attachment.")
return
}
@@ -242,10 +242,10 @@ func CreateReleaseAttachment(ctx *context.APIContext) {
})
if err != nil {
if upload.IsErrFileTypeForbidden(err) {
- ctx.Error(http.StatusBadRequest, "DetectContentType", err)
+ ctx.APIError(http.StatusBadRequest, err)
return
}
- ctx.Error(http.StatusInternalServerError, "NewAttachment", err)
+ ctx.APIErrorInternal(err)
return
}
@@ -308,15 +308,15 @@ func EditReleaseAttachment(ctx *context.APIContext) {
attach, err := repo_model.GetAttachmentByID(ctx, attachID)
if err != nil {
if repo_model.IsErrAttachmentNotExist(err) {
- ctx.NotFound()
+ ctx.APIErrorNotFound()
return
}
- ctx.Error(http.StatusInternalServerError, "GetAttachmentByID", err)
+ ctx.APIErrorInternal(err)
return
}
if attach.ReleaseID != releaseID {
log.Info("User requested attachment is not in release, release_id %v, attachment_id: %v", releaseID, attachID)
- ctx.NotFound()
+ ctx.APIErrorNotFound()
return
}
// FIXME Should prove the existence of the given repo, but results in unnecessary database requests
@@ -326,10 +326,10 @@ func EditReleaseAttachment(ctx *context.APIContext) {
if err := attachment_service.UpdateAttachment(ctx, setting.Repository.Release.AllowedTypes, attach); err != nil {
if upload.IsErrFileTypeForbidden(err) {
- ctx.Error(http.StatusUnprocessableEntity, "", err)
+ ctx.APIError(http.StatusUnprocessableEntity, err)
return
}
- ctx.Error(http.StatusInternalServerError, "UpdateAttachment", attach)
+ ctx.APIErrorInternal(err)
return
}
ctx.JSON(http.StatusCreated, convert.ToAPIAttachment(ctx.Repo.Repository, attach))
@@ -381,21 +381,21 @@ func DeleteReleaseAttachment(ctx *context.APIContext) {
attach, err := repo_model.GetAttachmentByID(ctx, attachID)
if err != nil {
if repo_model.IsErrAttachmentNotExist(err) {
- ctx.NotFound()
+ ctx.APIErrorNotFound()
return
}
- ctx.Error(http.StatusInternalServerError, "GetAttachmentByID", err)
+ ctx.APIErrorInternal(err)
return
}
if attach.ReleaseID != releaseID {
log.Info("User requested attachment is not in release, release_id %v, attachment_id: %v", releaseID, attachID)
- ctx.NotFound()
+ ctx.APIErrorNotFound()
return
}
// FIXME Should prove the existence of the given repo, but results in unnecessary database requests
if err := repo_model.DeleteAttachment(ctx, attach, true); err != nil {
- ctx.Error(http.StatusInternalServerError, "DeleteAttachment", err)
+ ctx.APIErrorInternal(err)
return
}
ctx.Status(http.StatusNoContent)