replace AbortWithError calls by custom function that sets the content type correctly

This commit is contained in:
Markus Muellner
2022-10-26 17:13:37 +02:00
committed by Benj Fassbind
parent 81582bffd2
commit ecc41f0c0f
11 changed files with 116 additions and 111 deletions
+16 -16
View File
@@ -52,7 +52,7 @@ func apiReposCreate(c *gin.Context) {
collection := collectionFactory.LocalRepoCollection()
err := collection.Add(repo)
if err != nil {
c.AbortWithError(400, err)
AbortWithJSONError(c, 400, err)
return
}
@@ -77,7 +77,7 @@ func apiReposEdit(c *gin.Context) {
repo, err := collection.ByName(c.Params.ByName("name"))
if err != nil {
c.AbortWithError(404, err)
AbortWithJSONError(c, 404, err)
return
}
@@ -85,7 +85,7 @@ func apiReposEdit(c *gin.Context) {
_, err := collection.ByName(*b.Name)
if err == nil {
// already exists
c.AbortWithError(404, err)
AbortWithJSONError(c, 404, err)
return
}
repo.Name = *b.Name
@@ -102,7 +102,7 @@ func apiReposEdit(c *gin.Context) {
err = collection.Update(repo)
if err != nil {
c.AbortWithError(500, err)
AbortWithJSONError(c, 500, err)
return
}
@@ -116,7 +116,7 @@ func apiReposShow(c *gin.Context) {
repo, err := collection.ByName(c.Params.ByName("name"))
if err != nil {
c.AbortWithError(404, err)
AbortWithJSONError(c, 404, err)
return
}
@@ -135,7 +135,7 @@ func apiReposDrop(c *gin.Context) {
repo, err := collection.ByName(name)
if err != nil {
c.AbortWithError(404, err)
AbortWithJSONError(c, 404, err)
return
}
@@ -165,13 +165,13 @@ func apiReposPackagesShow(c *gin.Context) {
repo, err := collection.ByName(c.Params.ByName("name"))
if err != nil {
c.AbortWithError(404, err)
AbortWithJSONError(c, 404, err)
return
}
err = collection.LoadComplete(repo)
if err != nil {
c.AbortWithError(500, err)
AbortWithJSONError(c, 500, err)
return
}
@@ -193,13 +193,13 @@ func apiReposPackagesAddDelete(c *gin.Context, taskNamePrefix string, cb func(li
repo, err := collection.ByName(c.Params.ByName("name"))
if err != nil {
c.AbortWithError(404, err)
AbortWithJSONError(c, 404, err)
return
}
err = collection.LoadComplete(repo)
if err != nil {
c.AbortWithError(500, err)
AbortWithJSONError(c, 500, err)
return
}
@@ -274,7 +274,7 @@ func apiReposPackageFromDir(c *gin.Context) {
dirParam := c.Params.ByName("dir")
fileParam := c.Params.ByName("file")
if fileParam != "" && !verifyPath(fileParam) {
c.AbortWithError(400, fmt.Errorf("wrong file"))
AbortWithJSONError(c, 400, fmt.Errorf("wrong file"))
return
}
@@ -284,13 +284,13 @@ func apiReposPackageFromDir(c *gin.Context) {
name := c.Params.ByName("name")
repo, err := collection.ByName(name)
if err != nil {
c.AbortWithError(404, err)
AbortWithJSONError(c, 404, err)
return
}
err = collection.LoadComplete(repo)
if err != nil {
c.AbortWithError(500, err)
AbortWithJSONError(c, 500, err)
return
}
@@ -407,7 +407,7 @@ func apiReposIncludePackageFromDir(c *gin.Context) {
dirParam := c.Params.ByName("dir")
fileParam := c.Params.ByName("file")
if fileParam != "" && !verifyPath(fileParam) {
c.AbortWithError(400, fmt.Errorf("wrong file"))
AbortWithJSONError(c, 400, fmt.Errorf("wrong file"))
return
}
@@ -421,7 +421,7 @@ func apiReposIncludePackageFromDir(c *gin.Context) {
repoTemplate, err := template.New("repo").Parse(repoTemplateString)
if err != nil {
c.AbortWithError(400, fmt.Errorf("error parsing repo template: %s", err))
AbortWithJSONError(c, 400, fmt.Errorf("error parsing repo template: %s", err))
return
}
@@ -432,7 +432,7 @@ func apiReposIncludePackageFromDir(c *gin.Context) {
// repo template string is simple text so only use resource key of specific repository
repo, err := collectionFactory.LocalRepoCollection().ByName(repoTemplateString)
if err != nil {
c.AbortWithError(404, err)
AbortWithJSONError(c, 404, err)
return
}