mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
API: Duplicate API Key Name Handle With Useful HTTP Code
This commit is contained in:
parent
164fb13d99
commit
da6df0ee07
@ -68,7 +68,10 @@ func (hs *HTTPServer) AddAPIKey(c *models.ReqContext, cmd models.AddApiKeyComman
|
||||
if err == models.ErrInvalidApiKeyExpiration {
|
||||
return Error(400, err.Error(), nil)
|
||||
}
|
||||
return Error(500, "Failed to add API key", err)
|
||||
if err.Error() == models.ErrDuplicateApiKey.Error() {
|
||||
return Error(409, "API Key Name Must Be Unique", nil)
|
||||
}
|
||||
return Error(500, "Failed to add API", err)
|
||||
}
|
||||
|
||||
result := &dtos.NewApiKeyResult{
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
|
||||
var ErrInvalidApiKey = errors.New("Invalid API Key")
|
||||
var ErrInvalidApiKeyExpiration = errors.New("Negative value for SecondsToLive")
|
||||
var ErrDuplicateApiKey = errors.New("UNIQUE constraint failed: api_key.org_id, api_key.name")
|
||||
|
||||
type ApiKey struct {
|
||||
Id int64
|
||||
|
Loading…
Reference in New Issue
Block a user