weldr/composeHandler: invert error handling
Check for errors and return early if they are found, rather than check for the absence of errors. This is not a functional change. Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
parent
f201fc84b7
commit
090d01602b
1 changed files with 25 additions and 25 deletions
|
|
@ -1409,31 +1409,7 @@ func (api *API) composeHandler(writer http.ResponseWriter, request *http.Request
|
|||
}
|
||||
|
||||
bp := api.store.GetBlueprintCommitted(cr.BlueprintName)
|
||||
if bp != nil {
|
||||
packages, buildPackages, err := api.depsolveBlueprint(bp, cr.ComposeType, api.arch.Name())
|
||||
if err != nil {
|
||||
errors := responseError{
|
||||
ID: "DepsolveError",
|
||||
Msg: err.Error(),
|
||||
}
|
||||
statusResponseError(writer, http.StatusInternalServerError, errors)
|
||||
return
|
||||
}
|
||||
|
||||
err = api.store.PushCompose(api.distro, reply.BuildID, bp, api.repos, packages, buildPackages, api.arch.Name(), cr.ComposeType, cr.Size, uploadTarget)
|
||||
|
||||
// TODO: we should probably do some kind of blueprint validation in future
|
||||
// for now, let's just 500 and bail out
|
||||
if err != nil {
|
||||
log.Println("error when pushing new compose: ", err.Error())
|
||||
errors := responseError{
|
||||
ID: "ComposePushErrored",
|
||||
Msg: err.Error(),
|
||||
}
|
||||
statusResponseError(writer, http.StatusInternalServerError, errors)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if bp == nil {
|
||||
errors := responseError{
|
||||
ID: "UnknownBlueprint",
|
||||
Msg: fmt.Sprintf("Unknown blueprint name: %s", cr.BlueprintName),
|
||||
|
|
@ -1442,6 +1418,30 @@ func (api *API) composeHandler(writer http.ResponseWriter, request *http.Request
|
|||
return
|
||||
}
|
||||
|
||||
packages, buildPackages, err := api.depsolveBlueprint(bp, cr.ComposeType, api.arch.Name())
|
||||
if err != nil {
|
||||
errors := responseError{
|
||||
ID: "DepsolveError",
|
||||
Msg: err.Error(),
|
||||
}
|
||||
statusResponseError(writer, http.StatusInternalServerError, errors)
|
||||
return
|
||||
}
|
||||
|
||||
err = api.store.PushCompose(api.distro, reply.BuildID, bp, api.repos, packages, buildPackages, api.arch.Name(), cr.ComposeType, cr.Size, uploadTarget)
|
||||
|
||||
// TODO: we should probably do some kind of blueprint validation in future
|
||||
// for now, let's just 500 and bail out
|
||||
if err != nil {
|
||||
log.Println("error when pushing new compose: ", err.Error())
|
||||
errors := responseError{
|
||||
ID: "ComposePushErrored",
|
||||
Msg: err.Error(),
|
||||
}
|
||||
statusResponseError(writer, http.StatusInternalServerError, errors)
|
||||
return
|
||||
}
|
||||
|
||||
err = json.NewEncoder(writer).Encode(reply)
|
||||
common.PanicOnError(err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue