feat: add HTTPError type for non-200 Grafana API responses (WH-4113)#7
Merged
Conversation
Replace plain fmt.Errorf strings with *HTTPError on all non-200 HTTP responses from the Grafana API. Callers can use errors.As to extract the status code and mirror it upstream instead of returning a generic 500. Backwards compatible: *HTTPError implements the error interface, so existing callers that only check err != nil or err.Error() are unaffected.
Author
|
@cursor review |
|
Skipping Bugbot: Bugbot is disabled for this repository. Visit the Bugbot dashboard to update your settings. |
There was a problem hiding this comment.
Pull request overview
This PR introduces a typed HTTPError error for non-200 responses from the Grafana API client so callers can reliably extract the upstream HTTP status code (via errors.As) instead of parsing fmt.Errorf strings.
Changes:
- Added exported
HTTPErrortype (status code + response body) implementingerror. - Updated Grafana client methods to return
*HTTPErroron non-200 HTTP responses (including reading the body first where needed).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/grafanadata/model.go | Adds exported HTTPError type implementing error with status code + body. |
| pkg/grafanadata/grafanadata.go | Replaces non-200 fmt.Errorf returns with *HTTPError across several client calls. |
| pkg/grafanadata/dashboard.go | Switches non-200 handling in FetchDashboards to return *HTTPError. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
eladda-weka
approved these changes
Jun 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
HTTPErrorstruct topkg/grafanadata/model.gowithStatusCode intandBody stringfieldsfmt.Errorfstrings with*HTTPErroron all non-200 HTTP responses acrossgetDashboard,getPanelData,getLabelValues,getDefaultDatasource, andFetchDashboardsBackwards compatibility
Fully backwards compatible.
*HTTPErrorimplements theerrorinterface so any caller checkingerr != nilor callingerr.Error()is unaffected. New callers can useerrors.Asto extract the status code and mirror it upstream rather than returning a generic 500.Usage