Skip to content

Commit

Permalink
events/controller: Update API query methods to return error with resp…
Browse files Browse the repository at this point in the history
…onse message
  • Loading branch information
joelrebel committed Jul 18, 2024
1 parent 84d3e84 commit d264c62
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
7 changes: 3 additions & 4 deletions events/controller/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,10 +507,9 @@ func (s *HTTPConditionStatusPublisher) Publish(ctx context.Context, serverID str
}

if resp.StatusCode != 200 {
// nolint:goerr113 // I'd like to keep the error definition close to where its in use.
errNon200 := fmt.Errorf("non 200 response code returned: %d", resp.StatusCode)
s.logger.Error(errNon200)
return errNon200
err := newQueryError(resp.StatusCode, resp.Message)
s.logger.WithError(errStatusPublish).Error(err)
return errors.Wrap(errStatusPublish, err.Error())
}

s.logger.WithFields(
Expand Down
2 changes: 1 addition & 1 deletion events/controller/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ func TestHTTPConditionStatusPublisher_Publish(t *testing.T) {
false,
).Return(&orctypes.ServerResponse{StatusCode: 400}, nil)
},
expectedError: "non 200 response code",
expectedError: "API Query returned error, status code: 400: condition status publish error",
},
}

Expand Down
14 changes: 6 additions & 8 deletions events/controller/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,9 @@ func (h *HTTPTaskRepository) Publish(ctx context.Context, task *condition.Task[a
}

if resp.StatusCode != 200 {
// nolint:goerr113 // I'd like to keep the error definition close to where its in use.
errNon200 := fmt.Errorf("non 200 response code returned: %d", resp.StatusCode)
h.logger.WithError(errTaskPublish).Error(errNon200)
return errors.Wrap(errTaskPublish, errNon200.Error())
err := newQueryError(resp.StatusCode, resp.Message)
h.logger.WithError(errTaskPublish).Error(err)
return errors.Wrap(errTaskPublish, err.Error())
}

h.logger.WithFields(
Expand Down Expand Up @@ -358,10 +357,9 @@ func (h *HTTPTaskRepository) Query(ctx context.Context) (*condition.Task[any, an
}

if resp.StatusCode != 200 {
// nolint:goerr113 // I'd like to keep the error definition close to where its in use.
errNon200 := fmt.Errorf("non 200 response code returned: %d", resp.StatusCode)
h.logger.WithError(errTaskQuery).Error(errNon200)
return nil, errors.Wrap(errTaskQuery, errNon200.Error())
err := newQueryError(resp.StatusCode, resp.Message)
h.logger.WithError(errTaskQuery).Error(err)
return nil, errors.Wrap(errTaskQuery, err.Error())
}

h.logger.WithFields(
Expand Down
4 changes: 2 additions & 2 deletions events/controller/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ func TestHTTPTaskRepository_Publish(t *testing.T) {
false,
).Return(&orctypes.ServerResponse{StatusCode: 400}, nil)
},
expectedError: "non 200 response code",
expectedError: "API Query returned error, status code: 400: task publish error",
},
}

Expand Down Expand Up @@ -799,7 +799,7 @@ func TestHTTPTaskRepository_Query(t *testing.T) {
Message: "Not Found",
}, nil)
},
expectedError: "non 200 response code",
expectedError: "API Query returned error, status code: 404, msg: Not Found: task query error",
},
}

Expand Down

0 comments on commit d264c62

Please sign in to comment.