From dbb4e9dfef0ba670b9d7b85e7c7e353e7a2cc0c4 Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Thu, 4 Jun 2020 12:29:37 +0300 Subject: [PATCH] refactor: errors --- pkg/datasource/datasource.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/datasource/datasource.go b/pkg/datasource/datasource.go index 35baa38..cec5c55 100644 --- a/pkg/datasource/datasource.go +++ b/pkg/datasource/datasource.go @@ -16,6 +16,11 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/data" ) +var ( + ErrFunctionsNotSupported = errors.New("zabbix queries with functions are not supported") + ErrNonMetricQueryNotSupported = errors.New("non-metrics queries are not supported") +) + type ZabbixDatasource struct { datasourceCache *cache.Cache logger log.Logger @@ -99,9 +104,9 @@ func (ds *ZabbixDatasource) QueryData(ctx context.Context, req *backend.QueryDat if err != nil { res.Error = err } else if len(query.Functions) > 0 { - res.Error = errors.New("Zabbix queries with functions are not supported") + res.Error = ErrFunctionsNotSupported } else if query.Mode != 0 { - res.Error = errors.New("Non-metrics queries are not supported") + res.Error = ErrNonMetricQueryNotSupported } else { frame, err := zabbixDS.queryNumericItems(ctx, &query) if err != nil {