-
Notifications
You must be signed in to change notification settings - Fork 11
Add top level errors conforming to http codes #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,10 @@ var ( | |
| RunnerExistsError = scalesetError("runner exists") | ||
| JobStillRunningError = scalesetError("job still running") | ||
| MessageQueueTokenExpiredError = scalesetError("message queue token expired") | ||
| // Top level errors carying the http status code meanings. | ||
| BadRequest = scalesetError("bad request") | ||
| NotFound = scalesetError("not found") | ||
| Unauthorized = scalesetError("unauthorized") | ||
|
||
| ) | ||
|
|
||
| type actionsExceptionError struct { | ||
|
|
@@ -87,12 +91,25 @@ func newRequestResponseError(req *http.Request, resp *http.Response, err error) | |
|
|
||
| switch { | ||
| case strings.Contains(exception.ExceptionName, "AgentExistsException"): | ||
| return fmt.Errorf("%s: %w: %s", sb.String(), RunnerExistsError, exception.Message) | ||
| return wrapResponseErrorType(resp, fmt.Errorf("%s: %w: %s", sb.String(), RunnerExistsError, exception.Message)) | ||
| case strings.Contains(exception.ExceptionName, "AgentNotFoundException"): | ||
| return fmt.Errorf("%s: %w: %s", sb.String(), RunnerNotFoundError, exception.Message) | ||
| return wrapResponseErrorType(resp, fmt.Errorf("%s: %w: %s", sb.String(), RunnerNotFoundError, exception.Message)) | ||
| case strings.Contains(exception.ExceptionName, "JobStillRunningException"): | ||
| return fmt.Errorf("%s: %w: %s", sb.String(), JobStillRunningError, exception.Message) | ||
| return wrapResponseErrorType(resp, fmt.Errorf("%s: %w: %s", sb.String(), JobStillRunningError, exception.Message)) | ||
| default: | ||
| return fmt.Errorf("%s: %w: %w", sb.String(), err, exception) | ||
| return wrapResponseErrorType(resp, fmt.Errorf("%s: %w: %w", sb.String(), err, exception)) | ||
|
Comment on lines
94
to
+101
|
||
| } | ||
| } | ||
|
|
||
| func wrapResponseErrorType(resp *http.Response, err error) error { | ||
| switch resp.StatusCode { | ||
| case http.StatusBadRequest: | ||
| return fmt.Errorf("%w: %w", BadRequest, err) | ||
| case http.StatusUnauthorized: | ||
| return fmt.Errorf("%w: %w", Unauthorized, err) | ||
| case http.StatusNotFound: | ||
| return fmt.Errorf("%w: %w", NotFound, err) | ||
| default: | ||
| return err | ||
| } | ||
|
Comment on lines
+105
to
117
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo/grammar in the new comment: "carying" -> "carrying", and "http" should be "HTTP" (also consider "Top-level").