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
+11 -6
View File
@@ -158,7 +158,7 @@ func maybeRunTaskInBackground(c *gin.Context, name string, resources []string, p
log.Println("Executing task asynchronously")
task, conflictErr := runTaskInBackground(name, resources, proc)
if conflictErr != nil {
c.AbortWithError(409, conflictErr)
AbortWithJSONError(c, 409, conflictErr)
return
}
c.JSON(202, task)
@@ -168,7 +168,7 @@ func maybeRunTaskInBackground(c *gin.Context, name string, resources []string, p
detail := task.Detail{}
retValue, err := proc(out, &detail)
if err != nil {
c.AbortWithError(retValue.Code, err)
AbortWithJSONError(c, retValue.Code, err)
return
}
if retValue != nil {
@@ -186,7 +186,7 @@ func showPackages(c *gin.Context, reflist *deb.PackageRefList, collectionFactory
list, err := deb.NewPackageListFromRefList(reflist, collectionFactory.PackageCollection(), nil)
if err != nil {
c.AbortWithError(404, err)
AbortWithJSONError(c, 404, err)
return
}
@@ -194,7 +194,7 @@ func showPackages(c *gin.Context, reflist *deb.PackageRefList, collectionFactory
if queryS != "" {
q, err := query.Parse(c.Request.URL.Query().Get("q"))
if err != nil {
c.AbortWithError(400, err)
AbortWithJSONError(c, 400, err)
return
}
@@ -211,7 +211,7 @@ func showPackages(c *gin.Context, reflist *deb.PackageRefList, collectionFactory
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
}
}
@@ -221,7 +221,7 @@ func showPackages(c *gin.Context, reflist *deb.PackageRefList, collectionFactory
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))
return
}
}
@@ -237,3 +237,8 @@ func showPackages(c *gin.Context, reflist *deb.PackageRefList, collectionFactory
c.JSON(200, list.Strings())
}
}
func AbortWithJSONError(c *gin.Context, code int, err error) *gin.Error {
c.Writer.Header().Set("Content-Type", "application/json; charset=utf-8")
return c.AbortWithError(code, err)
}
+12 -12
View File
@@ -24,7 +24,7 @@ func verifyPath(path string) bool {
func verifyDir(c *gin.Context) bool {
if !verifyPath(c.Params.ByName("dir")) {
c.AbortWithError(400, fmt.Errorf("wrong dir"))
AbortWithJSONError(c, 400, fmt.Errorf("wrong dir"))
return false
}
@@ -53,7 +53,7 @@ func apiFilesListDirs(c *gin.Context) {
})
if err != nil && !os.IsNotExist(err) {
c.AbortWithError(400, err)
AbortWithJSONError(c, 400, err)
return
}
@@ -70,13 +70,13 @@ func apiFilesUpload(c *gin.Context) {
err := os.MkdirAll(path, 0777)
if err != nil {
c.AbortWithError(500, err)
AbortWithJSONError(c, 500, err)
return
}
err = c.Request.ParseMultipartForm(10 * 1024 * 1024)
if err != nil {
c.AbortWithError(400, err)
AbortWithJSONError(c, 400, err)
return
}
@@ -86,7 +86,7 @@ func apiFilesUpload(c *gin.Context) {
for _, file := range files {
src, err := file.Open()
if err != nil {
c.AbortWithError(500, err)
AbortWithJSONError(c, 500, err)
return
}
defer src.Close()
@@ -94,14 +94,14 @@ func apiFilesUpload(c *gin.Context) {
destPath := filepath.Join(path, filepath.Base(file.Filename))
dst, err := os.Create(destPath)
if err != nil {
c.AbortWithError(500, err)
AbortWithJSONError(c, 500, err)
return
}
defer dst.Close()
_, err = io.Copy(dst, src)
if err != nil {
c.AbortWithError(500, err)
AbortWithJSONError(c, 500, err)
return
}
@@ -138,9 +138,9 @@ func apiFilesListFiles(c *gin.Context) {
if err != nil {
if os.IsNotExist(err) {
c.AbortWithError(404, err)
AbortWithJSONError(c, 404, err)
} else {
c.AbortWithError(500, err)
AbortWithJSONError(c, 500, err)
}
return
}
@@ -156,7 +156,7 @@ func apiFilesDeleteDir(c *gin.Context) {
err := os.RemoveAll(filepath.Join(context.UploadPath(), c.Params.ByName("dir")))
if err != nil {
c.AbortWithError(500, err)
AbortWithJSONError(c, 500, err)
return
}
@@ -170,14 +170,14 @@ func apiFilesDeleteFile(c *gin.Context) {
}
if !verifyPath(c.Params.ByName("name")) {
c.AbortWithError(400, fmt.Errorf("wrong file"))
AbortWithJSONError(c, 400, fmt.Errorf("wrong file"))
return
}
err := os.Remove(filepath.Join(context.UploadPath(), c.Params.ByName("dir"), c.Params.ByName("name")))
if err != nil {
if err1, ok := err.(*os.PathError); !ok || !os.IsNotExist(err1.Err) {
c.AbortWithError(500, err)
AbortWithJSONError(c, 500, err)
return
}
}
+5 -5
View File
@@ -38,7 +38,7 @@ func apiGPGAddKey(c *gin.Context) {
var tempdir string
tempdir, err = os.MkdirTemp(os.TempDir(), "aptly")
if err != nil {
c.AbortWithError(400, err)
AbortWithJSONError(c, 400, err)
return
}
defer os.RemoveAll(tempdir)
@@ -46,11 +46,11 @@ func apiGPGAddKey(c *gin.Context) {
keypath := filepath.Join(tempdir, "key")
keyfile, e := os.Create(keypath)
if e != nil {
c.AbortWithError(400, e)
AbortWithJSONError(c, 400, e)
return
}
if _, e = keyfile.WriteString(b.GpgKeyArmor); e != nil {
c.AbortWithError(400, e)
AbortWithJSONError(c, 400, e)
}
args = append(args, "--import", keypath)
@@ -64,7 +64,7 @@ func apiGPGAddKey(c *gin.Context) {
finder := pgp.GPG1Finder()
gpg, _, err := finder.FindGPG()
if err != nil {
c.AbortWithError(400, err)
AbortWithJSONError(c, 400, err)
return
}
@@ -75,7 +75,7 @@ func apiGPGAddKey(c *gin.Context) {
fmt.Printf("running %s %s\n", gpg, strings.Join(args, " "))
cmd.Stdout = os.Stdout
if err = cmd.Run(); err != nil {
c.AbortWithError(400, err)
AbortWithJSONError(c, 400, err)
return
}
+4 -4
View File
@@ -43,25 +43,25 @@ func apiGraph(c *gin.Context) {
stdin, err := command.StdinPipe()
if err != nil {
c.AbortWithError(500, err)
AbortWithJSONError(c, 500, err)
return
}
_, err = io.Copy(stdin, buf)
if err != nil {
c.AbortWithError(500, err)
AbortWithJSONError(c, 500, err)
return
}
err = stdin.Close()
if err != nil {
c.AbortWithError(500, err)
AbortWithJSONError(c, 500, err)
return
}
output, err = command.Output()
if err != nil {
c.AbortWithError(500, fmt.Errorf("unable to execute dot: %s (is graphviz package installed?)", err))
AbortWithJSONError(c, 500, fmt.Errorf("unable to execute dot: %s (is graphviz package installed?)", err))
return
}
+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
}
+1 -1
View File
@@ -9,7 +9,7 @@ func apiPackagesShow(c *gin.Context) {
collectionFactory := context.NewCollectionFactory()
p, err := collectionFactory.PackageCollection().ByKey([]byte(c.Params.ByName("key")))
if err != nil {
c.AbortWithError(404, err)
AbortWithJSONError(c, 404, err)
return
}
+18 -18
View File
@@ -71,7 +71,7 @@ func apiPublishList(c *gin.Context) {
})
if err != nil {
c.AbortWithError(500, err)
AbortWithJSONError(c, 500, err)
return
}
@@ -108,12 +108,12 @@ func apiPublishRepoOrSnapshot(c *gin.Context) {
signer, err := getSigner(&b.Signing)
if err != nil {
c.AbortWithError(500, fmt.Errorf("unable to initialize GPG signer: %s", err))
AbortWithJSONError(c, 500, fmt.Errorf("unable to initialize GPG signer: %s", err))
return
}
if len(b.Sources) == 0 {
c.AbortWithError(400, fmt.Errorf("unable to publish: soures are empty"))
AbortWithJSONError(c, 400, fmt.Errorf("unable to publish: soures are empty"))
return
}
@@ -134,14 +134,14 @@ func apiPublishRepoOrSnapshot(c *gin.Context) {
snapshot, err = snapshotCollection.ByName(source.Name)
if err != nil {
c.AbortWithError(404, fmt.Errorf("unable to publish: %s", err))
AbortWithJSONError(c, 404, fmt.Errorf("unable to publish: %s", err))
return
}
resources = append(resources, string(snapshot.ResourceKey()))
err = snapshotCollection.LoadComplete(snapshot)
if err != nil {
c.AbortWithError(500, fmt.Errorf("unable to publish: %s", err))
AbortWithJSONError(c, 500, fmt.Errorf("unable to publish: %s", err))
return
}
@@ -158,26 +158,26 @@ func apiPublishRepoOrSnapshot(c *gin.Context) {
localRepo, err = localCollection.ByName(source.Name)
if err != nil {
c.AbortWithError(404, fmt.Errorf("unable to publish: %s", err))
AbortWithJSONError(c, 404, fmt.Errorf("unable to publish: %s", err))
return
}
resources = append(resources, string(localRepo.Key()))
err = localCollection.LoadComplete(localRepo)
if err != nil {
c.AbortWithError(500, fmt.Errorf("unable to publish: %s", err))
AbortWithJSONError(c, 500, fmt.Errorf("unable to publish: %s", err))
}
sources = append(sources, localRepo)
}
} else {
c.AbortWithError(400, fmt.Errorf("unknown SourceKind"))
AbortWithJSONError(c, 400, fmt.Errorf("unknown SourceKind"))
return
}
published, err := deb.NewPublishedRepo(storage, prefix, b.Distribution, b.Architectures, components, sources, collectionFactory)
if err != nil {
c.AbortWithError(500, fmt.Errorf("unable to publish: %s", err))
AbortWithJSONError(c, 500, fmt.Errorf("unable to publish: %s", err))
return
}
@@ -264,7 +264,7 @@ func apiPublishUpdateSwitch(c *gin.Context) {
signer, err := getSigner(&b.Signing)
if err != nil {
c.AbortWithError(500, fmt.Errorf("unable to initialize GPG signer: %s", err))
AbortWithJSONError(c, 500, fmt.Errorf("unable to initialize GPG signer: %s", err))
return
}
@@ -273,12 +273,12 @@ func apiPublishUpdateSwitch(c *gin.Context) {
published, err := collection.ByStoragePrefixDistribution(storage, prefix, distribution)
if err != nil {
c.AbortWithError(404, fmt.Errorf("unable to update: %s", err))
AbortWithJSONError(c, 404, fmt.Errorf("unable to update: %s", err))
return
}
err = collection.LoadComplete(published, collectionFactory)
if err != nil {
c.AbortWithError(500, fmt.Errorf("unable to update: %s", err))
AbortWithJSONError(c, 500, fmt.Errorf("unable to update: %s", err))
return
}
@@ -288,7 +288,7 @@ func apiPublishUpdateSwitch(c *gin.Context) {
if published.SourceKind == deb.SourceLocalRepo {
if len(b.Snapshots) > 0 {
c.AbortWithError(400, fmt.Errorf("snapshots shouldn't be given when updating local repo"))
AbortWithJSONError(c, 400, fmt.Errorf("snapshots shouldn't be given when updating local repo"))
return
}
updatedComponents = published.Components()
@@ -299,20 +299,20 @@ func apiPublishUpdateSwitch(c *gin.Context) {
publishedComponents := published.Components()
for _, snapshotInfo := range b.Snapshots {
if !utils.StrSliceHasItem(publishedComponents, snapshotInfo.Component) {
c.AbortWithError(404, fmt.Errorf("component %s is not in published repository", snapshotInfo.Component))
AbortWithJSONError(c, 404, fmt.Errorf("component %s is not in published repository", snapshotInfo.Component))
return
}
snapshotCollection := collectionFactory.SnapshotCollection()
snapshot, err2 := snapshotCollection.ByName(snapshotInfo.Name)
if err2 != nil {
c.AbortWithError(404, err2)
AbortWithJSONError(c, 404, err2)
return
}
err2 = snapshotCollection.LoadComplete(snapshot)
if err2 != nil {
c.AbortWithError(500, err2)
AbortWithJSONError(c, 500, err2)
return
}
@@ -321,7 +321,7 @@ func apiPublishUpdateSwitch(c *gin.Context) {
updatedSnapshots = append(updatedSnapshots, snapshot.Name)
}
} else {
c.AbortWithError(500, fmt.Errorf("unknown published repository type"))
AbortWithJSONError(c, 500, fmt.Errorf("unknown published repository type"))
return
}
@@ -376,7 +376,7 @@ func apiPublishDrop(c *gin.Context) {
published, err := collection.ByStoragePrefixDistribution(storage, prefix, distribution)
if err != nil {
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("unable to drop: %s", err))
AbortWithJSONError(c, http.StatusInternalServerError, fmt.Errorf("unable to drop: %s", err))
return
}
+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
}
+2 -2
View File
@@ -45,7 +45,7 @@ func Router(c *ctx.AptlyContext) http.Handler {
err = <-errCh
if err != nil {
c.AbortWithError(500, err)
AbortWithJSONError(c, 500, err)
return
}
@@ -53,7 +53,7 @@ func Router(c *ctx.AptlyContext) http.Handler {
dbRequests <- dbRequest{releasedb, errCh}
err = <-errCh
if err != nil {
c.AbortWithError(500, err)
AbortWithJSONError(c, 500, err)
}
}()
+15 -15
View File
@@ -55,7 +55,7 @@ func apiSnapshotsCreateFromMirror(c *gin.Context) {
repo, err = collection.ByName(name)
if err != nil {
c.AbortWithError(404, err)
AbortWithJSONError(c, 404, err)
return
}
@@ -123,13 +123,13 @@ func apiSnapshotsCreate(c *gin.Context) {
for i := range b.SourceSnapshots {
sources[i], err = snapshotCollection.ByName(b.SourceSnapshots[i])
if err != nil {
c.AbortWithError(404, err)
AbortWithJSONError(c, 404, err)
return
}
err = snapshotCollection.LoadComplete(sources[i])
if err != nil {
c.AbortWithError(500, err)
AbortWithJSONError(c, 500, err)
return
}
@@ -188,7 +188,7 @@ func apiSnapshotsCreateFromRepository(c *gin.Context) {
repo, err = collection.ByName(name)
if err != nil {
c.AbortWithError(404, err)
AbortWithJSONError(c, 404, err)
return
}
@@ -240,7 +240,7 @@ func apiSnapshotsUpdate(c *gin.Context) {
snapshot, err = collection.ByName(name)
if err != nil {
c.AbortWithError(404, err)
AbortWithJSONError(c, 404, err)
return
}
@@ -275,13 +275,13 @@ func apiSnapshotsShow(c *gin.Context) {
snapshot, err := collection.ByName(c.Params.ByName("name"))
if err != nil {
c.AbortWithError(404, err)
AbortWithJSONError(c, 404, err)
return
}
err = collection.LoadComplete(snapshot)
if err != nil {
c.AbortWithError(500, err)
AbortWithJSONError(c, 500, err)
return
}
@@ -299,7 +299,7 @@ func apiSnapshotsDrop(c *gin.Context) {
snapshot, err := snapshotCollection.ByName(name)
if err != nil {
c.AbortWithError(404, err)
AbortWithJSONError(c, 404, err)
return
}
@@ -336,32 +336,32 @@ func apiSnapshotsDiff(c *gin.Context) {
snapshotA, err := collection.ByName(c.Params.ByName("name"))
if err != nil {
c.AbortWithError(404, err)
AbortWithJSONError(c, 404, err)
return
}
snapshotB, err := collection.ByName(c.Params.ByName("withSnapshot"))
if err != nil {
c.AbortWithError(404, err)
AbortWithJSONError(c, 404, err)
return
}
err = collection.LoadComplete(snapshotA)
if err != nil {
c.AbortWithError(500, err)
AbortWithJSONError(c, 500, err)
return
}
err = collection.LoadComplete(snapshotB)
if err != nil {
c.AbortWithError(500, err)
AbortWithJSONError(c, 500, err)
return
}
// Calculate diff
diff, err := snapshotA.RefList().Diff(snapshotB.RefList(), collectionFactory.PackageCollection())
if err != nil {
c.AbortWithError(500, err)
AbortWithJSONError(c, 500, err)
return
}
@@ -385,13 +385,13 @@ func apiSnapshotsSearchPackages(c *gin.Context) {
snapshot, err := collection.ByName(c.Params.ByName("name"))
if err != nil {
c.AbortWithError(404, err)
AbortWithJSONError(c, 404, err)
return
}
err = collection.LoadComplete(snapshot)
if err != nil {
c.AbortWithError(500, err)
AbortWithJSONError(c, 500, err)
return
}
+12 -12
View File
@@ -35,13 +35,13 @@ func apiTasksWaitForTaskByID(c *gin.Context) {
list := context.TaskList()
id, err := strconv.ParseInt(c.Params.ByName("id"), 10, 0)
if err != nil {
c.AbortWithError(500, err)
AbortWithJSONError(c, 500, err)
return
}
task, err := list.WaitForTaskByID(int(id))
if err != nil {
c.AbortWithError(400, err)
AbortWithJSONError(c, 400, err)
return
}
@@ -53,14 +53,14 @@ func apiTasksShow(c *gin.Context) {
list := context.TaskList()
id, err := strconv.ParseInt(c.Params.ByName("id"), 10, 0)
if err != nil {
c.AbortWithError(500, err)
AbortWithJSONError(c, 500, err)
return
}
var task task.Task
task, err = list.GetTaskByID(int(id))
if err != nil {
c.AbortWithError(404, err)
AbortWithJSONError(c, 404, err)
return
}
@@ -72,14 +72,14 @@ func apiTasksOutputShow(c *gin.Context) {
list := context.TaskList()
id, err := strconv.ParseInt(c.Params.ByName("id"), 10, 0)
if err != nil {
c.AbortWithError(500, err)
AbortWithJSONError(c, 500, err)
return
}
var output string
output, err = list.GetTaskOutputByID(int(id))
if err != nil {
c.AbortWithError(404, err)
AbortWithJSONError(c, 404, err)
return
}
@@ -91,14 +91,14 @@ func apiTasksDetailShow(c *gin.Context) {
list := context.TaskList()
id, err := strconv.ParseInt(c.Params.ByName("id"), 10, 0)
if err != nil {
c.AbortWithError(500, err)
AbortWithJSONError(c, 500, err)
return
}
var detail interface{}
detail, err = list.GetTaskDetailByID(int(id))
if err != nil {
c.AbortWithError(404, err)
AbortWithJSONError(c, 404, err)
return
}
@@ -110,13 +110,13 @@ func apiTasksReturnValueShow(c *gin.Context) {
list := context.TaskList()
id, err := strconv.ParseInt(c.Params.ByName("id"), 10, 0)
if err != nil {
c.AbortWithError(500, err)
AbortWithJSONError(c, 500, err)
return
}
output, err := list.GetTaskReturnValueByID(int(id))
if err != nil {
c.AbortWithError(404, err)
AbortWithJSONError(c, 404, err)
return
}
@@ -128,14 +128,14 @@ func apiTasksDelete(c *gin.Context) {
list := context.TaskList()
id, err := strconv.ParseInt(c.Params.ByName("id"), 10, 0)
if err != nil {
c.AbortWithError(500, err)
AbortWithJSONError(c, 500, err)
return
}
var delTask task.Task
delTask, err = list.DeleteTaskByID(int(id))
if err != nil {
c.AbortWithError(400, err)
AbortWithJSONError(c, 400, err)
return
}