LicenseStore migration to return plain errors (#14837)

Automatic Merge
This commit is contained in:
Rodrigo Villablanca
2020-06-23 23:56:35 -04:00
committed by GitHub
parent 668a2aa856
commit 64d12c08e9
7 changed files with 33 additions and 42 deletions

View File

@@ -4,7 +4,7 @@
package sqlstore
import (
"net/http"
"github.com/pkg/errors"
sq "github.com/Masterminds/squirrel"
@@ -39,7 +39,7 @@ func (ls SqlLicenseStore) createIndexesIfNotExists() {
// database it returns the license stored in the database. If not, it saves the
// new database and returns the created license with the CreateAt field
// updated.
func (ls SqlLicenseStore) Save(license *model.LicenseRecord) (*model.LicenseRecord, *model.AppError) {
func (ls SqlLicenseStore) Save(license *model.LicenseRecord) (*model.LicenseRecord, error) {
license.PreSave()
if err := license.IsValid(); err != nil {
return nil, err
@@ -50,13 +50,13 @@ func (ls SqlLicenseStore) Save(license *model.LicenseRecord) (*model.LicenseReco
Where(sq.Eq{"Id": license.Id})
queryString, args, err := query.ToSql()
if err != nil {
return nil, model.NewAppError("SqlLicenseStore.Save", "store.sql.build_query.app_error", nil, err.Error(), http.StatusInternalServerError)
return nil, errors.Wrap(err, "license_tosql")
}
var storedLicense model.LicenseRecord
if err := ls.GetReplica().SelectOne(&storedLicense, queryString, args...); err != nil {
// Only insert if not exists
if err := ls.GetMaster().Insert(license); err != nil {
return nil, model.NewAppError("SqlLicenseStore.Save", "store.sql_license.save.app_error", nil, "license_id="+license.Id+", "+err.Error(), http.StatusInternalServerError)
return nil, errors.Wrapf(err, "failed to get License with licenseId=%s", license.Id)
}
return license, nil
}
@@ -66,13 +66,13 @@ func (ls SqlLicenseStore) Save(license *model.LicenseRecord) (*model.LicenseReco
// Get obtains the license with the provided id parameter from the database.
// If the license doesn't exist it returns a model.AppError with
// http.StatusNotFound in the StatusCode field.
func (ls SqlLicenseStore) Get(id string) (*model.LicenseRecord, *model.AppError) {
func (ls SqlLicenseStore) Get(id string) (*model.LicenseRecord, error) {
obj, err := ls.GetReplica().Get(model.LicenseRecord{}, id)
if err != nil {
return nil, model.NewAppError("SqlLicenseStore.Get", "store.sql_license.get.app_error", nil, "license_id="+id+", "+err.Error(), http.StatusInternalServerError)
return nil, errors.Wrapf(err, "failed to get License with licenseId=%s", id)
}
if obj == nil {
return nil, model.NewAppError("SqlLicenseStore.Get", "store.sql_license.get.missing.app_error", nil, "license_id="+id, http.StatusNotFound)
return nil, store.NewErrNotFound("License", id)
}
return obj.(*model.LicenseRecord), nil
}