mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
17447: make changes requested during review
- use dialect.IsUniqueContraintViolation - change if statement to match others - return error properly
This commit is contained in:
parent
da6df0ee07
commit
a4a674ea83
@ -68,8 +68,8 @@ func (hs *HTTPServer) AddAPIKey(c *models.ReqContext, cmd models.AddApiKeyComman
|
|||||||
if err == models.ErrInvalidApiKeyExpiration {
|
if err == models.ErrInvalidApiKeyExpiration {
|
||||||
return Error(400, err.Error(), nil)
|
return Error(400, err.Error(), nil)
|
||||||
}
|
}
|
||||||
if err.Error() == models.ErrDuplicateApiKey.Error() {
|
if err == models.ErrDuplicateApiKey {
|
||||||
return Error(409, "API Key Name Must Be Unique", nil)
|
return Error(409, err.Error(), nil)
|
||||||
}
|
}
|
||||||
return Error(500, "Failed to add API", err)
|
return Error(500, "Failed to add API", err)
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
|
|
||||||
var ErrInvalidApiKey = errors.New("Invalid API Key")
|
var ErrInvalidApiKey = errors.New("Invalid API Key")
|
||||||
var ErrInvalidApiKeyExpiration = errors.New("Negative value for SecondsToLive")
|
var ErrInvalidApiKeyExpiration = errors.New("Negative value for SecondsToLive")
|
||||||
var ErrDuplicateApiKey = errors.New("UNIQUE constraint failed: api_key.org_id, api_key.name")
|
var ErrDuplicateApiKey = errors.New("API Key Organization ID And Name Must Be Unique")
|
||||||
|
|
||||||
type ApiKey struct {
|
type ApiKey struct {
|
||||||
Id int64
|
Id int64
|
||||||
|
@ -56,6 +56,9 @@ func AddApiKey(cmd *models.AddApiKeyCommand) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if _, err := sess.Insert(&t); err != nil {
|
if _, err := sess.Insert(&t); err != nil {
|
||||||
|
if dialect.IsUniqueConstraintViolation((err)) {
|
||||||
|
return models.ErrDuplicateApiKey
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
cmd.Result = &t
|
cmd.Result = &t
|
||||||
|
Loading…
Reference in New Issue
Block a user