From d571c714edabd1bb00e8e645f7a4c910b1ffa44c Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Thu, 6 Feb 2020 17:39:15 +0100 Subject: [PATCH] backend/builds: error handling fixes --- backend/builds/ghactions/client.go | 11 +++++++++++ backend/builds/service/service.go | 5 ++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/backend/builds/ghactions/client.go b/backend/builds/ghactions/client.go index 647197571c..f87223c57e 100644 --- a/backend/builds/ghactions/client.go +++ b/backend/builds/ghactions/client.go @@ -56,6 +56,10 @@ func (c *Client) ListWorkflowRuns(ctx context.Context, owner, repo string) (*Wor } defer res.Body.Close() + if res.StatusCode != http.StatusOK { + return nil, fmt.Errorf("Upstream fetch failed with status %d %s", res.StatusCode, res.Status) + } + var resData WorkflowRunsListResponse if err := json.NewDecoder(res.Body).Decode(&resData); err != nil { return nil, err @@ -76,6 +80,13 @@ func (c *Client) GetWorkflowRun(ctx context.Context, owner, repo, runId string) } defer res.Body.Close() + if res.StatusCode != http.StatusOK { + if res.StatusCode == http.StatusNotFound { + return nil, nil + } + return nil, fmt.Errorf("Upstream fetch failed with status %d %s", res.StatusCode, res.Status) + } + var resData WorkflowRunResponse if err := json.NewDecoder(res.Body).Decode(&resData); err != nil { return nil, err diff --git a/backend/builds/service/service.go b/backend/builds/service/service.go index 1b10fda980..4a2712b238 100644 --- a/backend/builds/service/service.go +++ b/backend/builds/service/service.go @@ -55,6 +55,9 @@ func (s *service) GetBuild(ctx context.Context, req *buildsv1.GetBuildRequest) ( if err != nil { return nil, status.Errorf(codes.Internal, "Failed to fetch workflow run for %s/%s/%s, %s", owner, repo, runID, err) } + if run == nil { + return nil, status.Errorf(codes.NotFound, "Workflow run %s/%s/%s not found", owner, repo, runID) + } return &buildsv1.GetBuildReply{ Build: s.transformBuild(owner, repo, run), @@ -108,7 +111,7 @@ func (s *service) parseBuildURI(uri string) (owner, repo, runID string, err erro } match := entityURIRegex.FindStringSubmatch(uri) - if err != nil { + if match == nil { return "", "", "", fmt.Errorf("uri does not match") }