mirror of
https://github.com/grafana/grafana.git
synced 2026-07-30 00:08:10 -05:00
[dashboard api] manage error when data in dashboard table is not valid json (#29999)
* retrieve dashboard api * Apply suggestions from code review Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> * Update pkg/api/dashboard.go Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
co-authored by
Arve Knudsen
parent
db67e70ba4
commit
388d00873f
@@ -54,6 +54,20 @@ func (hs *HTTPServer) GetDashboard(c *models.ReqContext) Response {
|
||||
return rsp
|
||||
}
|
||||
|
||||
// When dash contains only keys id, uid that means dashboard data is not valid and json decode failed.
|
||||
if dash.Data != nil {
|
||||
isEmptyData := true
|
||||
for k := range dash.Data.MustMap() {
|
||||
if k != "id" && k != "uid" {
|
||||
isEmptyData = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if isEmptyData {
|
||||
return Error(500, "Error while loading dashboard, dashboard data is invalid", nil)
|
||||
}
|
||||
}
|
||||
|
||||
guardian := guardian.New(dash.Id, c.OrgId, c.SignedInUser)
|
||||
if canView, err := guardian.CanView(); err != nil || !canView {
|
||||
return dashboardGuardianResponse(err)
|
||||
|
||||
@@ -1009,7 +1009,9 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
return nil
|
||||
})
|
||||
bus.AddHandler("test", func(query *models.GetDashboardQuery) error {
|
||||
query.Result = &models.Dashboard{Id: 1, Data: &simplejson.Json{}}
|
||||
dataValue, err := simplejson.NewJson([]byte(`{"id": 1, "editable": true, "style": "dark"}`))
|
||||
require.NoError(t, err)
|
||||
query.Result = &models.Dashboard{Id: 1, Data: dataValue}
|
||||
return nil
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user