improve error management of cscli bouncers add (#495)

This commit is contained in:
Thibault "bui" Koechlin 2020-12-01 16:16:01 +01:00 committed by GitHub
parent e5487aacdb
commit b7190c9ecc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 3 deletions

View file

@ -109,7 +109,7 @@ cscli bouncers add MyBouncerName -l 24`,
}
err = dbClient.CreateBouncer(keyName, keyIP, middlewares.HashSHA512(apiKey))
if err != nil {
log.Errorf("unable to create blocker: %s", err)
log.Errorf("unable to create bouncer: %s", err)
return
}
@ -143,7 +143,7 @@ cscli bouncers add MyBouncerName -l 24`,
}
err := dbClient.DeleteBouncer(keyName)
if err != nil {
log.Errorf("unable to create blocker: %s", err)
log.Errorf("unable to delete bouncer: %s", err)
return
}
},

View file

@ -269,7 +269,7 @@ cscli machines add MyTestMachine --password MyPassword
machineID = args[0]
err := dbClient.DeleteWatcher(machineID)
if err != nil {
log.Errorf("unable to create blocker: %s", err)
log.Errorf("unable to delete machine: %s", err)
return
}
log.Infof("machine '%s' deleted successfully", machineID)

View file

@ -34,6 +34,9 @@ func (c *Client) CreateBouncer(name string, ipAddr string, apiKey string) error
SetRevoked(false).
Save(c.CTX)
if err != nil {
if ent.IsConstraintError(err) {
return fmt.Errorf("bouncer %s already exists", name)
}
return fmt.Errorf("unable to save api key in database: %s", err)
}
return nil