diff --git a/pkg/tsdb/elasticsearch/client/client.go b/pkg/tsdb/elasticsearch/client/client.go index 73d03dcba7b..62f9ba2ee29 100644 --- a/pkg/tsdb/elasticsearch/client/client.go +++ b/pkg/tsdb/elasticsearch/client/client.go @@ -135,7 +135,7 @@ func (c *baseClientImpl) executeRequest(method, uriPath, uriQuery string, body [ c.logger.Debug("Sending request to Elasticsearch", "url", c.ds.URL) u, err := url.Parse(c.ds.URL) if err != nil { - return nil, err + return nil, backend.DownstreamError(fmt.Errorf("URL could not be parsed: %w", err)) } u.Path = path.Join(u.Path, uriPath) u.RawQuery = uriQuery diff --git a/pkg/tsdb/elasticsearch/data_query.go b/pkg/tsdb/elasticsearch/data_query.go index 79a9f5adb38..1c48b6e1326 100644 --- a/pkg/tsdb/elasticsearch/data_query.go +++ b/pkg/tsdb/elasticsearch/data_query.go @@ -3,10 +3,13 @@ package elasticsearch import ( "context" "encoding/json" + "errors" "fmt" + "net/url" "regexp" "slices" "strconv" + "strings" "time" "github.com/grafana/grafana-plugin-sdk-go/backend" @@ -82,6 +85,13 @@ func (e *elasticsearchDataQuery) execute() (*backend.QueryDataResponse, error) { if backend.IsDownstreamHTTPError(err) { err = backend.DownstreamError(err) } + var urlErr *url.Error + if errors.As(err, &urlErr) { + // Unsupported protocol scheme is a common error when the URL is not valid and should be treated as a downstream error + if urlErr.Err != nil && strings.HasPrefix(urlErr.Err.Error(), "unsupported protocol scheme") { + err = backend.DownstreamError(err) + } + } response.Responses[e.dataQueries[0].RefID] = backend.ErrorResponseWithErrorSource(err) return response, nil }