improve error management of cscli bouncers add (#495)
This commit is contained in:
parent
e5487aacdb
commit
b7190c9ecc
|
@ -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
|
||||
}
|
||||
},
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue