From c4a33206cee36fe6627ec9c2d204bbe6b4e8990d Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Sat, 29 Apr 2017 16:56:31 -0400 Subject: [PATCH] api: properly check for errors This results in NPE when cl.Info() returns an error. --- pkg/api/api.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pkg/api/api.go b/pkg/api/api.go index 0a573e9..8009f3c 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -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()