backend/builds: error handling fixes
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user