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
+20 -20
View File
@@ -81,7 +81,7 @@ func apiMirrorsCreate(c *gin.Context) {
if strings.HasPrefix(b.ArchiveURL, "ppa:") {
b.ArchiveURL, b.Distribution, b.Components, err = deb.ParsePPA(b.ArchiveURL, context.Config())
if err != nil {
c.AbortWithError(400, err)
AbortWithJSONError(c, 400, err)
return
}
}
@@ -89,7 +89,7 @@ func apiMirrorsCreate(c *gin.Context) {
if b.Filter != "" {
_, err = query.Parse(b.Filter)
if err != nil {
c.AbortWithError(400, fmt.Errorf("unable to create mirror: %s", err))
AbortWithJSONError(c, 400, fmt.Errorf("unable to create mirror: %s", err))
return
}
}
@@ -98,7 +98,7 @@ func apiMirrorsCreate(c *gin.Context) {
b.DownloadSources, b.DownloadUdebs, b.DownloadInstaller)
if err != nil {
c.AbortWithError(400, fmt.Errorf("unable to create mirror: %s", err))
AbortWithJSONError(c, 400, fmt.Errorf("unable to create mirror: %s", err))
return
}
@@ -110,20 +110,20 @@ func apiMirrorsCreate(c *gin.Context) {
verifier, err := getVerifier(b.IgnoreSignatures, b.Keyrings)
if err != nil {
c.AbortWithError(400, fmt.Errorf("unable to initialize GPG verifier: %s", err))
AbortWithJSONError(c, 400, fmt.Errorf("unable to initialize GPG verifier: %s", err))
return
}
downloader := context.NewDownloader(nil)
err = repo.Fetch(downloader, verifier)
if err != nil {
c.AbortWithError(400, fmt.Errorf("unable to fetch mirror: %s", err))
AbortWithJSONError(c, 400, fmt.Errorf("unable to fetch mirror: %s", err))
return
}
err = collection.Add(repo)
if err != nil {
c.AbortWithError(500, fmt.Errorf("unable to add mirror: %s", err))
AbortWithJSONError(c, 500, fmt.Errorf("unable to add mirror: %s", err))
return
}
@@ -141,7 +141,7 @@ func apiMirrorsDrop(c *gin.Context) {
repo, err := mirrorCollection.ByName(name)
if err != nil {
c.AbortWithError(404, fmt.Errorf("unable to drop: %s", err))
AbortWithJSONError(c, 404, fmt.Errorf("unable to drop: %s", err))
return
}
@@ -177,13 +177,13 @@ func apiMirrorsShow(c *gin.Context) {
name := c.Params.ByName("name")
repo, err := collection.ByName(name)
if err != nil {
c.AbortWithError(404, fmt.Errorf("unable to show: %s", err))
AbortWithJSONError(c, 404, fmt.Errorf("unable to show: %s", err))
return
}
err = collection.LoadComplete(repo)
if err != nil {
c.AbortWithError(500, fmt.Errorf("unable to show: %s", err))
AbortWithJSONError(c, 500, fmt.Errorf("unable to show: %s", err))
}
c.JSON(200, repo)
@@ -197,17 +197,17 @@ func apiMirrorsPackages(c *gin.Context) {
name := c.Params.ByName("name")
repo, err := collection.ByName(name)
if err != nil {
c.AbortWithError(404, fmt.Errorf("unable to show: %s", err))
AbortWithJSONError(c, 404, fmt.Errorf("unable to show: %s", err))
return
}
err = collection.LoadComplete(repo)
if err != nil {
c.AbortWithError(500, fmt.Errorf("unable to show: %s", err))
AbortWithJSONError(c, 500, fmt.Errorf("unable to show: %s", err))
}
if repo.LastDownloadDate.IsZero() {
c.AbortWithError(404, fmt.Errorf("unable to show package list, mirror hasn't been downloaded yet"))
AbortWithJSONError(c, 404, fmt.Errorf("unable to show package list, mirror hasn't been downloaded yet"))
return
}
@@ -216,7 +216,7 @@ func apiMirrorsPackages(c *gin.Context) {
list, err := deb.NewPackageListFromRefList(reflist, collectionFactory.PackageCollection(), nil)
if err != nil {
c.AbortWithError(404, err)
AbortWithJSONError(c, 404, err)
return
}
@@ -224,7 +224,7 @@ func apiMirrorsPackages(c *gin.Context) {
if queryS != "" {
q, err := query.Parse(c.Request.URL.Query().Get("q"))
if err != nil {
c.AbortWithError(400, err)
AbortWithJSONError(c, 400, err)
return
}
@@ -241,7 +241,7 @@ func apiMirrorsPackages(c *gin.Context) {
sort.Strings(architecturesList)
if len(architecturesList) == 0 {
c.AbortWithError(400, fmt.Errorf("unable to determine list of architectures, please specify explicitly"))
AbortWithJSONError(c, 400, fmt.Errorf("unable to determine list of architectures, please specify explicitly"))
return
}
}
@@ -251,7 +251,7 @@ func apiMirrorsPackages(c *gin.Context) {
list, err = list.Filter([]deb.PackageQuery{q}, withDeps,
nil, context.DependencyOptions(), architecturesList)
if err != nil {
c.AbortWithError(500, fmt.Errorf("unable to search: %s", err))
AbortWithJSONError(c, 500, fmt.Errorf("unable to search: %s", err))
}
}
@@ -296,7 +296,7 @@ func apiMirrorsUpdate(c *gin.Context) {
remote, err = collection.ByName(c.Params.ByName("name"))
if err != nil {
c.AbortWithError(404, err)
AbortWithJSONError(c, 404, err)
return
}
@@ -318,14 +318,14 @@ func apiMirrorsUpdate(c *gin.Context) {
if b.Name != remote.Name {
_, err = collection.ByName(b.Name)
if err == nil {
c.AbortWithError(409, fmt.Errorf("unable to rename: mirror %s already exists", b.Name))
AbortWithJSONError(c, 409, fmt.Errorf("unable to rename: mirror %s already exists", b.Name))
return
}
}
if b.DownloadUdebs != remote.DownloadUdebs {
if remote.IsFlat() && b.DownloadUdebs {
c.AbortWithError(400, fmt.Errorf("unable to update: flat mirrors don't support udebs"))
AbortWithJSONError(c, 400, fmt.Errorf("unable to update: flat mirrors don't support udebs"))
return
}
}
@@ -345,7 +345,7 @@ func apiMirrorsUpdate(c *gin.Context) {
verifier, err := getVerifier(b.IgnoreSignatures, b.Keyrings)
if err != nil {
c.AbortWithError(400, fmt.Errorf("unable to initialize GPG verifier: %s", err))
AbortWithJSONError(c, 400, fmt.Errorf("unable to initialize GPG verifier: %s", err))
return
}