-
Notifications
You must be signed in to change notification settings - Fork 5
fix: improve http status codes #215
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?
Conversation
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #215 +/- ##
==========================================
- Coverage 51.33% 51.33% -0.01%
==========================================
Files 56 56
Lines 8471 8552 +81
==========================================
+ Hits 4349 4390 +41
- Misses 3889 3922 +33
- Partials 233 240 +7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| // IsServerError returns true if the error is a server error | ||
| func (e *IBMError) IsServerError() bool { | ||
| return e.Type == ErrorTypeServerError || (e.StatusCode >= 500 && e.StatusCode < 600) | ||
| return e.Type == ErrorTypeServerError || (e.StatusCode >= http.StatusInternalServerError && e.StatusCode < 600) |
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.
can you double check if the StatusCode returns the correct type? I think it might in fact be a string which would make these comparisons false
| // extractStatusCodeFromString safely extracts HTTP status codes from error strings | ||
| func extractStatusCodeFromString(errStr string) int { | ||
| // Prefer phrase → code mappings first so we work without digits too. | ||
| switch { | ||
| case strings.Contains(errStr, "bad gateway"): | ||
| return http.StatusBadGateway // 502 | ||
| case strings.Contains(errStr, "service unavailable"): | ||
| return http.StatusServiceUnavailable // 503 | ||
| case strings.Contains(errStr, "gateway timeout"): | ||
| return http.StatusGatewayTimeout // 504 | ||
| case strings.Contains(errStr, "request timeout"): | ||
| return http.StatusRequestTimeout // 408 | ||
| case strings.Contains(errStr, "too many requests") || strings.Contains(errStr, "rate limit"): | ||
| return http.StatusTooManyRequests // 429 | ||
| case strings.Contains(errStr, "permission denied") || strings.Contains(errStr, "forbidden"): | ||
| return http.StatusForbidden // 403 | ||
| case strings.Contains(errStr, "authentication failed") || strings.Contains(errStr, "unauthorized"): | ||
| return http.StatusUnauthorized // 401 | ||
| case strings.Contains(errStr, "already exists") || strings.Contains(errStr, "conflict"): | ||
| return http.StatusConflict // 409 | ||
| case strings.Contains(errStr, "validation") || strings.Contains(errStr, "invalid"): | ||
| return http.StatusBadRequest // 400 | ||
| case strings.Contains(errStr, "not found") || strings.Contains(errStr, "not_found"): | ||
| return http.StatusNotFound // 404 | ||
| } | ||
|
|
||
| // Then look for explicit digits. | ||
| digitToStatus := map[string]int{ | ||
| "400": http.StatusBadRequest, | ||
| "401": http.StatusUnauthorized, | ||
| "403": http.StatusForbidden, | ||
| "404": http.StatusNotFound, | ||
| "408": http.StatusRequestTimeout, | ||
| "409": http.StatusConflict, | ||
| "422": http.StatusUnprocessableEntity, | ||
| "429": http.StatusTooManyRequests, | ||
| "500": http.StatusInternalServerError, | ||
| "502": http.StatusBadGateway, | ||
| "503": http.StatusServiceUnavailable, | ||
| "504": http.StatusGatewayTimeout, | ||
| } | ||
| for k, v := range digitToStatus { | ||
| if strings.Contains(errStr, k) { | ||
| return v | ||
| } | ||
| } | ||
| return 0 | ||
| } |
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.
why are we doing this? isn't this part of the library?
|
Unknown CLA label state. Rechecking for CLA labels. Send feedback to sig-contributor-experience at kubernetes/community. /check-cla |
|
PR needs rebase. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
/lifecycle stale |
|
The Kubernetes project currently lacks enough active contributors to adequately respond to all PRs. This bot triages PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle rotten |
Description
Type of change
Testing
helm lintand template validation)Checklist
Additional context