summaryrefslogtreecommitdiffstats
path: root/app/license.go
diff options
context:
space:
mode:
authorJesús Espino <jespinog@gmail.com>2018-09-28 16:55:14 +0200
committerGitHub <noreply@github.com>2018-09-28 16:55:14 +0200
commita551b375fa6bed975e8df88bf5d024df957a7684 (patch)
tree7170a88a044fa5b346af2f83396bb43b50e6fa4e /app/license.go
parentee672a72e4c534f2d5f36cc563084279ba31ba87 (diff)
downloadchat-a551b375fa6bed975e8df88bf5d024df957a7684.tar.gz
chat-a551b375fa6bed975e8df88bf5d024df957a7684.tar.bz2
chat-a551b375fa6bed975e8df88bf5d024df957a7684.zip
Idiomatic error handling for app/{job,license,login}.go (#9474)
Diffstat (limited to 'app/license.go')
-rw-r--r--app/license.go64
1 files changed, 31 insertions, 33 deletions
diff --git a/app/license.go b/app/license.go
index 310a61fdb..ec18ec318 100644
--- a/app/license.go
+++ b/app/license.go
@@ -46,46 +46,44 @@ func (a *App) LoadLicense() {
}
func (a *App) SaveLicense(licenseBytes []byte) (*model.License, *model.AppError) {
- var license *model.License
-
- if success, licenseStr := utils.ValidateLicense(licenseBytes); success {
- license = model.LicenseFromJson(strings.NewReader(licenseStr))
+ success, licenseStr := utils.ValidateLicense(licenseBytes)
+ if !success {
+ return nil, model.NewAppError("addLicense", model.INVALID_LICENSE_ERROR, nil, "", http.StatusBadRequest)
+ }
+ license := model.LicenseFromJson(strings.NewReader(licenseStr))
- if result := <-a.Srv.Store.User().AnalyticsUniqueUserCount(""); result.Err != nil {
- return nil, model.NewAppError("addLicense", "api.license.add_license.invalid_count.app_error", nil, result.Err.Error(), http.StatusBadRequest)
- } else {
- uniqueUserCount := result.Data.(int64)
+ result := <-a.Srv.Store.User().AnalyticsUniqueUserCount("")
+ if result.Err != nil {
+ return nil, model.NewAppError("addLicense", "api.license.add_license.invalid_count.app_error", nil, result.Err.Error(), http.StatusBadRequest)
+ }
+ uniqueUserCount := result.Data.(int64)
- if uniqueUserCount > int64(*license.Features.Users) {
- return nil, model.NewAppError("addLicense", "api.license.add_license.unique_users.app_error", map[string]interface{}{"Users": *license.Features.Users, "Count": uniqueUserCount}, "", http.StatusBadRequest)
- }
- }
+ if uniqueUserCount > int64(*license.Features.Users) {
+ return nil, model.NewAppError("addLicense", "api.license.add_license.unique_users.app_error", map[string]interface{}{"Users": *license.Features.Users, "Count": uniqueUserCount}, "", http.StatusBadRequest)
+ }
- if ok := a.SetLicense(license); !ok {
- return nil, model.NewAppError("addLicense", model.EXPIRED_LICENSE_ERROR, nil, "", http.StatusBadRequest)
- }
+ if ok := a.SetLicense(license); !ok {
+ return nil, model.NewAppError("addLicense", model.EXPIRED_LICENSE_ERROR, nil, "", http.StatusBadRequest)
+ }
- record := &model.LicenseRecord{}
- record.Id = license.Id
- record.Bytes = string(licenseBytes)
- rchan := a.Srv.Store.License().Save(record)
+ record := &model.LicenseRecord{}
+ record.Id = license.Id
+ record.Bytes = string(licenseBytes)
+ rchan := a.Srv.Store.License().Save(record)
- if result := <-rchan; result.Err != nil {
- a.RemoveLicense()
- return nil, model.NewAppError("addLicense", "api.license.add_license.save.app_error", nil, "err="+result.Err.Error(), http.StatusInternalServerError)
- }
+ if result := <-rchan; result.Err != nil {
+ a.RemoveLicense()
+ return nil, model.NewAppError("addLicense", "api.license.add_license.save.app_error", nil, "err="+result.Err.Error(), http.StatusInternalServerError)
+ }
- sysVar := &model.System{}
- sysVar.Name = model.SYSTEM_ACTIVE_LICENSE_ID
- sysVar.Value = license.Id
- schan := a.Srv.Store.System().SaveOrUpdate(sysVar)
+ sysVar := &model.System{}
+ sysVar.Name = model.SYSTEM_ACTIVE_LICENSE_ID
+ sysVar.Value = license.Id
+ schan := a.Srv.Store.System().SaveOrUpdate(sysVar)
- if result := <-schan; result.Err != nil {
- a.RemoveLicense()
- return nil, model.NewAppError("addLicense", "api.license.add_license.save_active.app_error", nil, "", http.StatusInternalServerError)
- }
- } else {
- return nil, model.NewAppError("addLicense", model.INVALID_LICENSE_ERROR, nil, "", http.StatusBadRequest)
+ if result := <-schan; result.Err != nil {
+ a.RemoveLicense()
+ return nil, model.NewAppError("addLicense", "api.license.add_license.save_active.app_error", nil, "", http.StatusInternalServerError)
}
a.ReloadConfig()