DS-Apiservers: fix error handling in ds apiservers (#111956)

This commit is contained in:
Sarah Zinger 2025-10-02 15:40:30 -04:00 committed by GitHub
parent 0af6efb096
commit 74a2232de1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 17 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/backend"
data "github.com/grafana/grafana-plugin-sdk-go/experimental/apis/data/v0alpha1"
"github.com/grafana/grafana/pkg/apimachinery/errutil"
query "github.com/grafana/grafana/pkg/apis/query/v0alpha1"
query_headers "github.com/grafana/grafana/pkg/registry/apis/query"
"github.com/grafana/grafana/pkg/services/datasources"
@ -96,6 +97,22 @@ func (r *subQueryREST) Connect(ctx context.Context, name string, opts runtime.Ob
PluginContext: pluginCtx,
Headers: query_headers.ExtractKnownHeaders(req.Header),
})
// all errors get converted into k8 errors when sent in responder.Error and lose important context like downstream info
var e errutil.Error
if errors.As(err, &e) && e.Source == errutil.SourceDownstream {
responder.Object(int(backend.StatusBadRequest),
&query.QueryDataResponse{QueryDataResponse: backend.QueryDataResponse{Responses: map[string]backend.DataResponse{
"A": {
Error: errors.New(e.LogMessage),
ErrorSource: backend.ErrorSourceDownstream,
Status: backend.StatusBadRequest,
},
}}},
)
return
}
if err != nil {
responder.Error(err)
return