Unverified Commit 9d73c79d authored by Jesús Espino's avatar Jesús Espino Committed by GitHub

Idiomatic error handling for app/c*.go (#9423)

parent 8898d7aa
......@@ -81,9 +81,8 @@ func (me *ClusterDiscoveryService) Stop() {
func (a *App) IsLeader() bool {
if a.License() != nil && *a.Config().ClusterSettings.Enable && a.Cluster != nil {
return a.Cluster.IsLeader()
} else {
return true
}
return true
}
func (a *App) GetClusterId() string {
......
......@@ -16,11 +16,11 @@ func (a *App) GetComplianceReports(page, perPage int) (model.Compliances, *model
return nil, model.NewAppError("GetComplianceReports", "ent.compliance.licence_disable.app_error", nil, "", http.StatusNotImplemented)
}
if result := <-a.Srv.Store.Compliance().GetAll(page*perPage, perPage); result.Err != nil {
result := <-a.Srv.Store.Compliance().GetAll(page*perPage, perPage)
if result.Err != nil {
return nil, result.Err
} else {
return result.Data.(model.Compliances), nil
}
return result.Data.(model.Compliances), nil
}
func (a *App) SaveComplianceReport(job *model.Compliance) (*model.Compliance, *model.AppError) {
......@@ -30,15 +30,16 @@ func (a *App) SaveComplianceReport(job *model.Compliance) (*model.Compliance, *m
job.Type = model.COMPLIANCE_TYPE_ADHOC
if result := <-a.Srv.Store.Compliance().Save(job); result.Err != nil {
result := <-a.Srv.Store.Compliance().Save(job)
if result.Err != nil {
return nil, result.Err
} else {
job = result.Data.(*model.Compliance)
a.Go(func() {
a.Compliance.RunComplianceJob(job)
})
}
job = result.Data.(*model.Compliance)
a.Go(func() {
a.Compliance.RunComplianceJob(job)
})
return job, nil
}
......@@ -47,17 +48,17 @@ func (a *App) GetComplianceReport(reportId string) (*model.Compliance, *model.Ap
return nil, model.NewAppError("downloadComplianceReport", "ent.compliance.licence_disable.app_error", nil, "", http.StatusNotImplemented)
}
if result := <-a.Srv.Store.Compliance().Get(reportId); result.Err != nil {
result := <-a.Srv.Store.Compliance().Get(reportId)
if result.Err != nil {
return nil, result.Err
} else {
return result.Data.(*model.Compliance), nil
}
return result.Data.(*model.Compliance), nil
}
func (a *App) GetComplianceFile(job *model.Compliance) ([]byte, *model.AppError) {
if f, err := ioutil.ReadFile(*a.Config().ComplianceSettings.Directory + "compliance/" + job.JobName() + ".zip"); err != nil {
f, err := ioutil.ReadFile(*a.Config().ComplianceSettings.Directory + "compliance/" + job.JobName() + ".zip")
if err != nil {
return nil, model.NewAppError("readFile", "api.file.read_file.reading_local.app_error", nil, err.Error(), http.StatusNotImplemented)
} else {
return f, nil
}
return f, nil
}
......@@ -185,7 +185,9 @@ func (a *App) ensureAsymmetricSigningKey() error {
result := <-a.Srv.Store.System().GetByName(model.SYSTEM_ASYMMETRIC_SIGNING_KEY)
if result.Err != nil {
return result.Err
} else if err := json.Unmarshal([]byte(result.Data.(*model.System).Value), &key); err != nil {
}
if err := json.Unmarshal([]byte(result.Data.(*model.System).Value), &key); err != nil {
return err
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment