From 0feb4e4d44f6e46686984b1602012f6e7898b88a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Budai?= Date: Fri, 1 Nov 2019 15:21:04 +0100 Subject: [PATCH] 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. --- internal/store/store.go | 2 +- internal/weldr/api.go | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/internal/store/store.go b/internal/store/store.go index 2438b6d43..0a24d1bdc 100644 --- a/internal/store/store.go +++ b/internal/store/store.go @@ -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{ diff --git a/internal/weldr/api.go b/internal/weldr/api.go index 7e9e370f3..c5985f0e9 100644 --- a/internal/weldr/api.go +++ b/internal/weldr/api.go @@ -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",