@@ -6,103 +6,73 @@ import (
66 "github.com/grafana/grafana-plugin-sdk-go/backend"
77)
88
9- func New (err error , source backend.ErrorSource , status backend.Status ) Error {
10- return Error {err : err , source : source , status : status }
11- }
12-
13- // Error captures error source and implements the error interface
14- type Error struct {
15- source backend.ErrorSource
16- status backend.Status
17-
18- err error
19- }
9+ type Error = backend.ErrorWithSource
2010
21- // Error implements the interface
22- func (r Error ) Error () string {
23- return r .err .Error ()
24- }
25-
26- // Unwrap implements the interface
27- func (r Error ) Unwrap () error {
28- return r .err
29- }
30-
31- // Source provides the error source
32- func (r Error ) Source () backend.ErrorSource {
33- return r .source
34- }
35-
36- func (r Error ) ErrorSource () backend.ErrorSource {
37- return r .source
11+ // New creates a new error with the source
12+ // Deprecated: use backend.NewErrorWithSource instead
13+ func New (err error , source backend.ErrorSource , _ backend.Status ) Error {
14+ // We are not using status here, but we are keeping it for compatibility
15+ return backend .NewErrorWithSource (err , source )
3816}
3917
4018// PluginError will apply the source as plugin
41- func PluginError (err error , override bool ) error {
19+ // Deprecated: use backend.PluginError instead
20+ func PluginError (err error , _ bool ) error {
4221 if err != nil {
43- return SourceError ( backend .ErrorSourcePlugin , err , override )
22+ return backend .PluginError ( err )
4423 }
4524 return nil
4625}
4726
4827// DownstreamError will apply the source as downstream
49- func DownstreamError (err error , override bool ) error {
28+ // Deprecated: use backend.DownstreamError instead
29+ func DownstreamError (err error , _ bool ) error {
5030 if err != nil {
51- return SourceError ( backend .ErrorSourceDownstream , err , override )
31+ return backend .DownstreamError ( err )
5232 }
5333 return nil
5434}
5535
5636// SourceError returns an error with the source
5737// If source is already defined, it will return it, or you can override
38+ // Deprecated: Use backend.DownstreamError or backend.PluginError instead
5839func SourceError (source backend.ErrorSource , err error , override bool ) Error {
5940 var sourceError Error
6041 if errors .As (err , & sourceError ) && ! override {
6142 return sourceError // already has a source
6243 }
63- return Error {
64- source : source ,
65- err : err ,
66- }
44+ return New (err , source , 0 )
6745}
6846
6947// Response returns an error DataResponse given status, source of the error and message.
48+ // Deprecated: Use backend.ErrorResponseWithErrorSource instead
7049func Response (err error ) backend.DataResponse {
71- var e Error
72- if ! errors .As (err , & e ) {
73- // generic error, default to "plugin" error source
74- return backend.DataResponse {
75- Error : err ,
76- ErrorSource : backend .ErrorSourcePlugin ,
77- Status : backend .StatusUnknown ,
78- }
79- }
80- return backend.DataResponse {
81- Error : err ,
82- ErrorSource : e .source ,
83- Status : e .status ,
84- }
50+ return backend .ErrorResponseWithErrorSource (err )
8551}
8652
8753// FromStatus returns error source from status
54+ // Deprecated: Use backend.ErrorSourceFromHTTPStatus instead
8855func FromStatus (status backend.Status ) backend.ErrorSource {
8956 return backend .ErrorSourceFromHTTPStatus (int (status ))
9057}
9158
9259// AddPluginErrorToResponse adds the error as plugin error source to the response
9360// if the error already has a source, the existing source will be used
61+ // Deprecated: Use backend.ErrorResponse instead
9462func AddPluginErrorToResponse (refID string , response * backend.QueryDataResponse , err error ) * backend.QueryDataResponse {
9563 return AddErrorToResponse (refID , response , PluginError (err , false ))
9664}
9765
9866// AddDownstreamErrorToResponse adds the error as downstream source to the response
9967// if the error already has a source, the existing source will be used
68+ // Deprecated: Use backend.ErrorResponse instead and set the response directly
10069func AddDownstreamErrorToResponse (refID string , response * backend.QueryDataResponse , err error ) * backend.QueryDataResponse {
10170 return AddErrorToResponse (refID , response , DownstreamError (err , false ))
10271}
10372
10473// AddErrorToResponse adds the error to the response
74+ // Deprecated: Use backend.ErrorResponse instead and set the response directly
10575func AddErrorToResponse (refID string , response * backend.QueryDataResponse , err error ) * backend.QueryDataResponse {
106- response .Responses [refID ] = Response (err )
76+ response .Responses [refID ] = backend . ErrorResponseWithErrorSource (err )
10777 return response
10878}
0 commit comments