Merge pull request #75 from spotify/rugvip/errors

builds: error handling fixes
This commit is contained in:
Patrik Oldsberg
2020-02-07 09:32:36 +01:00
committed by GitHub
4 changed files with 19 additions and 5 deletions
+11
View File
@@ -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
+4 -1
View File
@@ -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")
}
@@ -38,8 +38,8 @@ const BuildDetailsPage: FC<Props> = () => {
}
if (status.error) {
return (
<Typography variant="h4" color="error">
Failed to load build, {status.error}
<Typography variant="h6" color="error">
Failed to load build, {status.error.message}
</Typography>
);
}
@@ -36,8 +36,8 @@ const BuildListPage: FC<{}> = () => {
}
if (status.error) {
return (
<Typography variant="h4" color="error">
Failed to load builds, {status.error}
<Typography variant="h6" color="error">
Failed to load builds, {status.error.message}
</Typography>
);
}