Chore: Handle wrapped errors (#29223)

* Chore: Handle wrapped errors

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>

Co-authored-by: Emil Tullstedt <emil.tullstedt@grafana.com>
This commit is contained in:
Arve Knudsen
2020-11-19 13:34:28 +01:00
committed by GitHub
parent 0cb29d337a
commit 294770f411
34 changed files with 153 additions and 124 deletions

View File

@ -37,7 +37,7 @@ func (hs *HTTPServer) getPluginContext(pluginID string, user *models.SignedInUse
if err != nil {
// models.ErrPluginSettingNotFound is expected if there's no row found for plugin setting in database (if non-app plugin).
// If it's not this expected error something is wrong with cache or database and we return the error to the client.
if err != models.ErrPluginSettingNotFound {
if !errors.Is(err, models.ErrPluginSettingNotFound) {
return pc, errutil.Wrap("Failed to get plugin settings", err)
}
} else {
@ -166,7 +166,7 @@ func GetPluginSettingByID(c *models.ReqContext) Response {
query := models.GetPluginSettingByIdQuery{PluginId: pluginID, OrgId: c.OrgId}
if err := bus.Dispatch(&query); err != nil {
if err != models.ErrPluginSettingNotFound {
if !errors.Is(err, models.ErrPluginSettingNotFound) {
return Error(500, "Failed to get login settings", nil)
}
} else {
@ -200,8 +200,9 @@ func GetPluginDashboards(c *models.ReqContext) Response {
list, err := plugins.GetPluginDashboards(c.OrgId, pluginID)
if err != nil {
if notfound, ok := err.(plugins.PluginNotFoundError); ok {
return Error(404, notfound.Error(), nil)
var notFound plugins.PluginNotFoundError
if errors.As(err, &notFound) {
return Error(404, notFound.Error(), nil)
}
return Error(500, "Failed to get plugin dashboards", err)
@ -216,8 +217,9 @@ func GetPluginMarkdown(c *models.ReqContext) Response {
content, err := plugins.GetPluginMarkdown(pluginID, name)
if err != nil {
if notfound, ok := err.(plugins.PluginNotFoundError); ok {
return Error(404, notfound.Error(), nil)
var notFound plugins.PluginNotFoundError
if errors.As(err, &notFound) {
return Error(404, notFound.Error(), nil)
}
return Error(500, "Could not get markdown file", err)
@ -291,7 +293,7 @@ func (hs *HTTPServer) CheckHealth(c *models.ReqContext) Response {
pCtx, err := hs.getPluginContext(pluginID, c.SignedInUser)
if err != nil {
if err == ErrPluginNotFound {
if errors.Is(err, ErrPluginNotFound) {
return Error(404, "Plugin not found", nil)
}
@ -334,7 +336,7 @@ func (hs *HTTPServer) CallResource(c *models.ReqContext) {
pCtx, err := hs.getPluginContext(pluginID, c.SignedInUser)
if err != nil {
if err == ErrPluginNotFound {
if errors.Is(err, ErrPluginNotFound) {
c.JsonApiErr(404, "Plugin not found", nil)
return
}