Elasticsearch: Invalid URL and unsupported protocol should be downstream errors (#100886)
* Invalid URL and unsupported protocol should be downstream errors * Fix lint * Change from errors.Is to errors.As
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user