api: improve error handling when compose push fails
There was missing condition for the case when compose push fails. As the previous commit introduces customizations which can return even more errors it is important to report such errors. For now the API is returning only 500 HTTP code. In future we should distinguish between failures and blueprint validation errors.
This commit is contained in:
parent
913dc8d6c9
commit
0feb4e4d44
2 changed files with 14 additions and 2 deletions
|
|
@ -382,7 +382,7 @@ func (s *Store) PushCompose(composeID uuid.UUID, bp *blueprint.Blueprint, compos
|
|||
}
|
||||
pipeline, err := bp.ToPipeline(composeType)
|
||||
if err != nil {
|
||||
return &InvalidRequestError{"invalid output type: " + composeType}
|
||||
return err
|
||||
}
|
||||
s.change(func() error {
|
||||
s.Composes[composeID] = Compose{
|
||||
|
|
|
|||
|
|
@ -757,7 +757,19 @@ func (api *API) composeHandler(writer http.ResponseWriter, httpRequest *http.Req
|
|||
found := api.store.GetBlueprint(cr.BlueprintName, &bp, &changed) // TODO: what to do with changed?
|
||||
|
||||
if found {
|
||||
api.store.PushCompose(reply.BuildID, &bp, cr.ComposeType)
|
||||
err := api.store.PushCompose(reply.BuildID, &bp, cr.ComposeType)
|
||||
|
||||
// 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 {
|
||||
errors := responseError{
|
||||
ID: "UnknownBlueprint",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue