Alerting: unified alerting frontend (#32708)
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/go-openapi/strfmt"
|
||||
apimodels "github.com/grafana/alerting-api/pkg/api"
|
||||
@@ -45,7 +46,7 @@ func backendType(ctx *models.ReqContext, cache datasources.CacheService) (apimod
|
||||
switch ds.Type {
|
||||
case "loki", "prometheus":
|
||||
return apimodels.LoTexRulerBackend, nil
|
||||
case "grafana-alertmanager-datasource":
|
||||
case "alertmanager":
|
||||
return apimodels.AlertmanagerBackend, nil
|
||||
default:
|
||||
return 0, fmt.Errorf("unexpected backend type (%v)", ds.Type)
|
||||
@@ -94,7 +95,19 @@ func (p *AlertingProxy) withReq(
|
||||
|
||||
status := resp.Status()
|
||||
if status >= 400 {
|
||||
return response.Error(status, string(resp.Body()), nil)
|
||||
errMessage := string(resp.Body())
|
||||
// if Content-Type is application/json
|
||||
// and it is successfully decoded and contains a message
|
||||
// return this as response error message
|
||||
if strings.HasPrefix(resp.Header().Get("Content-Type"), "application/json") {
|
||||
var m map[string]interface{}
|
||||
if err := json.Unmarshal(resp.Body(), &m); err == nil {
|
||||
if message, ok := m["message"]; ok {
|
||||
errMessage = message.(string)
|
||||
}
|
||||
}
|
||||
}
|
||||
return response.Error(status, errMessage, nil)
|
||||
}
|
||||
|
||||
t, err := extractor(resp.Body())
|
||||
|
||||
Reference in New Issue
Block a user