Chore: Refactor backend plugin errors (#74928)

This commit is contained in:
Andres Martinez Gotor
2023-09-25 11:56:03 +02:00
committed by GitHub
parent 38d2357bb8
commit 1714fa598c
16 changed files with 102 additions and 130 deletions

View File

@ -11,7 +11,6 @@ import (
"github.com/grafana/grafana/pkg/api/response"
"github.com/grafana/grafana/pkg/middleware/requestmeta"
"github.com/grafana/grafana/pkg/plugins/backendplugin"
"github.com/grafana/grafana/pkg/plugins/httpresponsesender"
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
"github.com/grafana/grafana/pkg/services/datasources"
@ -125,16 +124,6 @@ func (hs *HTTPServer) makePluginResourceRequest(w http.ResponseWriter, req *http
}
func handleCallResourceError(err error, reqCtx *contextmodel.ReqContext) {
if errors.Is(err, backendplugin.ErrPluginUnavailable) {
reqCtx.JsonApiErr(http.StatusServiceUnavailable, "Plugin unavailable", err)
return
}
if errors.Is(err, backendplugin.ErrMethodNotImplemented) {
reqCtx.JsonApiErr(http.StatusNotFound, "Not found", err)
return
}
resp := response.ErrOrFallback(http.StatusInternalServerError, "Failed to call resource", err)
resp.WriteTo(reqCtx)
}