switch to json resp for errors (#36743)

This commit is contained in:
Will Browne 2021-07-14 23:56:11 -07:00 committed by GitHub
parent 9b329804e1
commit e82f8dbef9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -261,7 +261,7 @@ func (hs *HTTPServer) GetPluginAssets(c *models.ReqContext) {
pluginID := c.Params("pluginId")
plugin := hs.PluginManager.GetPlugin(pluginID)
if plugin == nil {
c.Handle(hs.Cfg, 404, "Plugin not found", nil)
c.JsonApiErr(404, "Plugin not found", nil)
return
}
@ -274,10 +274,10 @@ func (hs *HTTPServer) GetPluginAssets(c *models.ReqContext) {
f, err := os.Open(pluginFilePath)
if err != nil {
if os.IsNotExist(err) {
c.Handle(hs.Cfg, 404, "Plugin file not found", err)
c.JsonApiErr(404, "Plugin file not found", err)
return
}
c.Handle(hs.Cfg, 500, "Could not open plugin file", err)
c.JsonApiErr(500, "Could not open plugin file", err)
return
}
defer func() {
@ -288,12 +288,12 @@ func (hs *HTTPServer) GetPluginAssets(c *models.ReqContext) {
fi, err := f.Stat()
if err != nil {
c.Handle(hs.Cfg, 500, "Plugin file exists but could not open", err)
c.JsonApiErr(500, "Plugin file exists but could not open", err)
return
}
if shouldExclude(fi) {
c.Handle(hs.Cfg, 403, "Plugin file access forbidden",
c.JsonApiErr(403, "Plugin file access forbidden",
fmt.Errorf("access is forbidden to executable plugin file %s", pluginFilePath))
return
}