api: properly check for errors

This results in NPE when cl.Info() returns an error.
This commit is contained in:
Tamir Duberstein 2017-04-29 16:56:31 -04:00
parent 6289e479a5
commit c4a33206ce
No known key found for this signature in database
GPG Key ID: 1C1E98CC8E17BB89

View File

@ -109,11 +109,11 @@ func Connect(c *gin.Context) {
info, err := cl.Info()
if err == nil {
err = setClient(c, cl)
if err != nil {
cl.Close()
c.JSON(400, Error{err.Error()})
return
}
}
if err != nil {
cl.Close()
c.JSON(400, Error{err.Error()})
return
}
c.JSON(200, info.Format()[0])
@ -163,11 +163,11 @@ func SwitchDb(c *gin.Context) {
info, err := cl.Info()
if err == nil {
err = setClient(c, cl)
if err != nil {
cl.Close()
c.JSON(400, Error{err.Error()})
return
}
}
if err != nil {
cl.Close()
c.JSON(400, Error{err.Error()})
return
}
conn.Close()