PublicDashboards: refactor using new grafana error types (#58078)

This commit is contained in:
Ezequiel Victorero
2022-11-04 14:14:32 -03:00
committed by GitHub
parent 5f5b3521d9
commit ae30a0688a
12 changed files with 267 additions and 300 deletions

View File

@@ -1,15 +1,13 @@
package validation
import (
"fmt"
"github.com/grafana/grafana/pkg/models"
. "github.com/grafana/grafana/pkg/services/publicdashboards/models"
)
func ValidatePublicDashboard(dto *SavePublicDashboardDTO, dashboard *models.Dashboard) error {
if hasTemplateVariables(dashboard) {
return ErrPublicDashboardHasTemplateVariables
return ErrPublicDashboardHasTemplateVariables.Errorf("ValidateSavePublicDashboard: public dashboard has template variables")
}
return nil
@@ -23,11 +21,11 @@ func hasTemplateVariables(dashboard *models.Dashboard) bool {
func ValidateQueryPublicDashboardRequest(req PublicDashboardQueryDTO) error {
if req.IntervalMs < 0 {
return fmt.Errorf("intervalMS should be greater than 0")
return ErrInvalidInterval.Errorf("ValidateQueryPublicDashboardRequest: intervalMS should be greater than 0")
}
if req.MaxDataPoints < 0 {
return fmt.Errorf("maxDataPoints should be greater than 0")
return ErrInvalidMaxDataPoints.Errorf("ValidateQueryPublicDashboardRequest: maxDataPoints should be greater than 0")
}
return nil