Return a 400 instead of a 500 for empty query (#98841)

This commit is contained in:
Sarah Zinger
2025-01-13 14:58:13 -05:00
committed by GitHub
parent ab6d82a33c
commit 210d73188d
2 changed files with 13 additions and 5 deletions
+8 -1
View File
@@ -124,7 +124,14 @@ func (s *Service) QueryData(ctx context.Context, req *backend.QueryDataRequest)
logger.Warn("Found query models without targets", "models without targets", strings.Join(emptyQueries, "\n"))
// If no queries had a valid target, return an error; otherwise, attempt with the targets we have
if len(emptyQueries) == len(req.Queries) {
return &result, errors.New("no query target found for the alert rule")
if result.Responses == nil {
result.Responses = make(map[string]backend.DataResponse)
}
// marking this downstream error as it is a user error, but arguably this is a plugin error
// since the plugin should have frontend validation that prevents us from getting into this state
missingQueryResponse := backend.ErrDataResponseWithSource(400, backend.ErrorSourceDownstream, "no query target found for the alert rule")
result.Responses["A"] = missingQueryResponse
return &result, nil
}
}
formData["target"] = targetList