Skip to content

feat: add HTTPError type for non-200 Grafana API responses (WH-4113)#7

Merged
danielBWeka merged 1 commit into
mainfrom
danielb/http-error-WH-4113
Jun 17, 2026
Merged

feat: add HTTPError type for non-200 Grafana API responses (WH-4113)#7
danielBWeka merged 1 commit into
mainfrom
danielb/http-error-WH-4113

Conversation

@danielBWeka

Copy link
Copy Markdown

Summary

  • Adds exported HTTPError struct to pkg/grafanadata/model.go with StatusCode int and Body string fields
  • Replaces plain fmt.Errorf strings with *HTTPError on all non-200 HTTP responses across getDashboard, getPanelData, getLabelValues, getDefaultDatasource, and FetchDashboards

Backwards compatibility

Fully backwards compatible. *HTTPError implements the error interface so any caller checking err != nil or calling err.Error() is unaffected. New callers can use errors.As to extract the status code and mirror it upstream rather than returning a generic 500.

Usage

var httpErr *grafanadata.HTTPError
if errors.As(err, &httpErr) {
    // mirror httpErr.StatusCode back to the caller
}

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.
@danielBWeka danielBWeka requested a review from Copilot June 15, 2026 10:04
@danielBWeka

Copy link
Copy Markdown
Author

@cursor review

@cursor

cursor Bot commented Jun 15, 2026

Copy link
Copy Markdown

Skipping Bugbot: Bugbot is disabled for this repository. Visit the Bugbot dashboard to update your settings.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 HTTPError type (status code + response body) implementing error.
  • Updated Grafana client methods to return *HTTPError on 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.

Comment thread pkg/grafanadata/dashboard.go
Comment thread pkg/grafanadata/model.go
@danielBWeka danielBWeka requested a review from eladda-weka June 15, 2026 10:09
@danielBWeka danielBWeka merged commit ae71676 into main Jun 17, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants