From d81a61398d01d839e70e2345da787e7ef89c0832 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Espino?= Date: Wed, 1 Aug 2018 16:55:18 +0200 Subject: Migrate all the api4 to handle errors in idiomatic way (#9143) --- api4/system.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'api4/system.go') diff --git a/api4/system.go b/api4/system.go index 68f998d6d..9177b8940 100644 --- a/api4/system.go +++ b/api4/system.go @@ -341,20 +341,21 @@ func addLicense(c *Context, w http.ResponseWriter, r *http.Request) { buf := bytes.NewBuffer(nil) io.Copy(buf, file) - if license, err := c.App.SaveLicense(buf.Bytes()); err != nil { - if err.Id == model.EXPIRED_LICENSE_ERROR { + license, appErr := c.App.SaveLicense(buf.Bytes()) + if appErr != nil { + if appErr.Id == model.EXPIRED_LICENSE_ERROR { c.LogAudit("failed - expired or non-started license") - } else if err.Id == model.INVALID_LICENSE_ERROR { + } else if appErr.Id == model.INVALID_LICENSE_ERROR { c.LogAudit("failed - invalid license") } else { c.LogAudit("failed - unable to save license") } - c.Err = err + c.Err = appErr return - } else { - c.LogAudit("success") - w.Write([]byte(license.ToJson())) } + + c.LogAudit("success") + w.Write([]byte(license.ToJson())) } func removeLicense(c *Context, w http.ResponseWriter, r *http.Request) { -- cgit v1.2.3-1-g7c22