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:
co-authored by
Emil Tullstedt
parent
0cb29d337a
commit
294770f411
+3
-2
@@ -1,6 +1,7 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
@@ -70,10 +71,10 @@ func (hs *HTTPServer) AddAPIKey(c *models.ReqContext, cmd models.AddApiKeyComman
|
||||
cmd.Key = newKeyInfo.HashedKey
|
||||
|
||||
if err := bus.Dispatch(&cmd); err != nil {
|
||||
if err == models.ErrInvalidApiKeyExpiration {
|
||||
if errors.Is(err, models.ErrInvalidApiKeyExpiration) {
|
||||
return Error(400, err.Error(), nil)
|
||||
}
|
||||
if err == models.ErrDuplicateApiKey {
|
||||
if errors.Is(err, models.ErrDuplicateApiKey) {
|
||||
return Error(409, err.Error(), nil)
|
||||
}
|
||||
return Error(500, "Failed to add API Key", err)
|
||||
|
||||
Reference in New Issue
Block a user