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:
Tom Gundersen 2020-03-22 20:48:26 +01:00 committed by msehnout
parent f201fc84b7
commit 090d01602b

View file

@ -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)
}