Commit a6918617 by Torkel Ödegaard

feat(api): fixed minor issue with error message when trying to create duplicate…

feat(api): fixed minor issue with error message when trying to create duplicate datasource, fixes #6164
parent 4f226355
...@@ -92,6 +92,11 @@ func AddDataSource(c *middleware.Context, cmd m.AddDataSourceCommand) { ...@@ -92,6 +92,11 @@ func AddDataSource(c *middleware.Context, cmd m.AddDataSourceCommand) {
cmd.OrgId = c.OrgId cmd.OrgId = c.OrgId
if err := bus.Dispatch(&cmd); err != nil { if err := bus.Dispatch(&cmd); err != nil {
if err == m.ErrDataSourceNameExists {
c.JsonApiErr(409, err.Error(), err)
return
}
c.JsonApiErr(500, "Failed to add datasource", err) c.JsonApiErr(500, "Failed to add datasource", err)
return return
} }
......
...@@ -22,7 +22,8 @@ const ( ...@@ -22,7 +22,8 @@ const (
// Typed errors // Typed errors
var ( var (
ErrDataSourceNotFound = errors.New("Data source not found") ErrDataSourceNotFound = errors.New("Data source not found")
ErrDataSourceNameExists = errors.New("Data source with same name already exists")
) )
type DsAccess string type DsAccess string
......
...@@ -60,6 +60,14 @@ func DeleteDataSource(cmd *m.DeleteDataSourceCommand) error { ...@@ -60,6 +60,14 @@ func DeleteDataSource(cmd *m.DeleteDataSourceCommand) error {
func AddDataSource(cmd *m.AddDataSourceCommand) error { func AddDataSource(cmd *m.AddDataSourceCommand) error {
return inTransaction(func(sess *xorm.Session) error { return inTransaction(func(sess *xorm.Session) error {
existing := m.DataSource{OrgId: cmd.OrgId, Name: cmd.Name}
has, _ := x.Get(&existing)
if has {
return m.ErrDataSourceNameExists
}
ds := &m.DataSource{ ds := &m.DataSource{
OrgId: cmd.OrgId, OrgId: cmd.OrgId,
Name: cmd.Name, Name: cmd.Name,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment