diff --git a/apier/v1/accounts.go b/apier/v1/accounts.go
index c85d61a75..874f29cf6 100644
--- a/apier/v1/accounts.go
+++ b/apier/v1/accounts.go
@@ -19,9 +19,8 @@ along with this program. If not, see
package v1
import (
- "errors"
- "fmt"
"regexp"
+ "strings"
"time"
"github.com/cgrates/cgrates/engine"
@@ -43,12 +42,12 @@ type AccountActionTiming struct {
func (self *ApierV1) GetAccountActionPlan(attrs AttrAcntAction, reply *[]*AccountActionTiming) error {
if missing := utils.MissingStructFields(&attrs, []string{"Tenant", "Account", "Direction"}); len(missing) != 0 {
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(strings.Join(missing, ","), "")
}
accountATs := make([]*AccountActionTiming, 0)
allATs, err := self.AccountDb.GetAllActionPlans()
if err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
for _, ats := range allATs {
for _, at := range ats {
@@ -73,11 +72,11 @@ type AttrRemActionTiming struct {
// Removes an ActionTimings or parts of it depending on filters being set
func (self *ApierV1) RemActionTiming(attrs AttrRemActionTiming, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"ActionPlanId"}); len(missing) != 0 { // Only mandatory ActionPlanId
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if len(attrs.Account) != 0 { // Presence of Account requires complete account details to be provided
if missing := utils.MissingStructFields(&attrs, []string{"Tenant", "Account", "Direction"}); len(missing) != 0 {
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
}
_, err := engine.AccLock.Guard(func() (interface{}, error) {
@@ -85,7 +84,7 @@ func (self *ApierV1) RemActionTiming(attrs AttrRemActionTiming, reply *string) e
if err != nil {
return 0, err
} else if len(ats) == 0 {
- return 0, errors.New(utils.ERR_NOT_FOUND)
+ return 0, utils.ErrNotFound
}
ats = engine.RemActionPlan(ats, attrs.ActionTimingId, utils.AccountKey(attrs.Tenant, attrs.Account, attrs.Direction))
if err := self.AccountDb.SetActionPlans(attrs.ActionPlanId, ats); err != nil {
@@ -94,7 +93,7 @@ func (self *ApierV1) RemActionTiming(attrs AttrRemActionTiming, reply *string) e
return 0, nil
}, engine.ACTION_TIMING_PREFIX)
if err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
if attrs.ReloadScheduler && self.Sched != nil {
self.Sched.LoadActionPlans(self.AccountDb)
@@ -107,10 +106,10 @@ func (self *ApierV1) RemActionTiming(attrs AttrRemActionTiming, reply *string) e
// Returns a list of ActionTriggers on an account
func (self *ApierV1) GetAccountActionTriggers(attrs AttrAcntAction, reply *engine.ActionTriggerPriotityList) error {
if missing := utils.MissingStructFields(&attrs, []string{"Tenant", "Account", "Direction"}); len(missing) != 0 {
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if balance, err := self.AccountDb.GetAccount(utils.AccountKey(attrs.Tenant, attrs.Account, attrs.Direction)); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else {
*reply = balance.ActionTriggers
}
@@ -127,7 +126,7 @@ type AttrRemAcntActionTriggers struct {
// Returns a list of ActionTriggers on an account
func (self *ApierV1) RemAccountActionTriggers(attrs AttrRemAcntActionTriggers, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"Tenant", "Account", "Direction"}); len(missing) != 0 {
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
balanceId := utils.AccountKey(attrs.Tenant, attrs.Account, attrs.Direction)
_, err := engine.AccLock.Guard(func() (interface{}, error) {
@@ -152,7 +151,7 @@ func (self *ApierV1) RemAccountActionTriggers(attrs AttrRemAcntActionTriggers, r
return 0, nil
}, balanceId)
if err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
*reply = OK
return nil
@@ -161,7 +160,7 @@ func (self *ApierV1) RemAccountActionTriggers(attrs AttrRemAcntActionTriggers, r
// Ads a new account into dataDb. If already defined, returns success.
func (self *ApierV1) SetAccount(attr utils.AttrSetAccount, reply *string) error {
if missing := utils.MissingStructFields(&attr, []string{"Tenant", "Direction", "Account"}); len(missing) != 0 {
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
balanceId := utils.AccountKey(attr.Tenant, attr.Account, attr.Direction)
var ub *engine.Account
@@ -193,7 +192,7 @@ func (self *ApierV1) SetAccount(attr utils.AttrSetAccount, reply *string) error
return 0, nil
}, balanceId)
if err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
if len(ats) != 0 {
_, err := engine.AccLock.Guard(func() (interface{}, error) { // ToDo: Try locking it above on read somehow
@@ -203,7 +202,7 @@ func (self *ApierV1) SetAccount(attr utils.AttrSetAccount, reply *string) error
return 0, nil
}, engine.ACTION_TIMING_PREFIX)
if err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
if self.Sched != nil {
self.Sched.LoadActionPlans(self.AccountDb)
@@ -224,7 +223,7 @@ type AttrGetAccounts struct {
func (self *ApierV1) GetAccounts(attr AttrGetAccounts, reply *[]*engine.Account) error {
if len(attr.Tenant) == 0 {
- return fmt.Errorf("%s:Tenant", utils.ERR_MANDATORY_IE_MISSING)
+ return utils.NewErrMandatoryIeMissing("Tenanat")
}
if len(attr.Direction) == 0 {
attr.Direction = utils.OUT
@@ -254,7 +253,7 @@ func (self *ApierV1) GetAccounts(attr AttrGetAccounts, reply *[]*engine.Account)
}
retAccounts := make([]*engine.Account, 0)
for _, acntKey := range limitedAccounts {
- if acnt, err := self.AccountDb.GetAccount(acntKey[len(engine.ACCOUNT_PREFIX):]); err != nil && err.Error() != utils.ERR_NOT_FOUND { // Not found is not an error here
+ if acnt, err := self.AccountDb.GetAccount(acntKey[len(engine.ACCOUNT_PREFIX):]); err != nil && err != utils.ErrNotFound { // Not found is not an error here
return err
} else if acnt != nil {
retAccounts = append(retAccounts, acnt)
diff --git a/apier/v1/aliases.go b/apier/v1/aliases.go
index 0ff869316..9e8577201 100644
--- a/apier/v1/aliases.go
+++ b/apier/v1/aliases.go
@@ -19,9 +19,6 @@ along with this program. If not, see
package v1
import (
- "errors"
- "fmt"
-
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
@@ -39,18 +36,18 @@ type AttrAddAccountAliases struct {
// Retrieve aliases configured for a rating profile subject
func (self *ApierV1) AddRatingSubjectAliases(attrs AttrAddRatingSubjectAliases, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"Tenant", "Subject", "Aliases"}); len(missing) != 0 {
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
aliasesChanged := []string{}
for _, alias := range attrs.Aliases {
if err := self.RatingDb.SetRpAlias(utils.RatingSubjectAliasKey(attrs.Tenant, alias), attrs.Subject); err != nil {
- return fmt.Errorf("%s:%s:%s", utils.ERR_SERVER_ERROR, alias, err.Error())
+ return utils.NewErrServerError(err)
}
aliasesChanged = append(aliasesChanged, engine.RP_ALIAS_PREFIX+utils.RatingSubjectAliasKey(attrs.Tenant, alias))
}
didNotChange := []string{}
if err := self.RatingDb.CacheRating(didNotChange, didNotChange, didNotChange, aliasesChanged, didNotChange, didNotChange); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
*reply = utils.OK
return nil
@@ -59,12 +56,12 @@ func (self *ApierV1) AddRatingSubjectAliases(attrs AttrAddRatingSubjectAliases,
// Retrieve aliases configured for a rating profile subject
func (self *ApierV1) GetRatingSubjectAliases(attrs engine.TenantRatingSubject, reply *[]string) error {
if missing := utils.MissingStructFields(&attrs, []string{"Tenant", "Subject"}); len(missing) != 0 {
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if aliases, err := self.RatingDb.GetRPAliases(attrs.Tenant, attrs.Subject, false); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if len(aliases) == 0 { // Need it since otherwise we get some unexpected errrors in the client
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
} else {
*reply = aliases
}
@@ -74,14 +71,14 @@ func (self *ApierV1) GetRatingSubjectAliases(attrs engine.TenantRatingSubject, r
// Retrieve aliases configured for a rating profile subject
func (self *ApierV1) RemRatingSubjectAliases(tenantRatingSubject engine.TenantRatingSubject, reply *string) error {
if missing := utils.MissingStructFields(&tenantRatingSubject, []string{"Tenant", "Subject"}); len(missing) != 0 {
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if err := self.RatingDb.RemoveRpAliases([]*engine.TenantRatingSubject{&tenantRatingSubject}); err != nil {
- return fmt.Errorf("%s:% s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
didNotChange := []string{}
if err := self.RatingDb.CacheRating(didNotChange, didNotChange, didNotChange, nil, didNotChange, didNotChange); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
*reply = utils.OK
return nil
@@ -89,18 +86,18 @@ func (self *ApierV1) RemRatingSubjectAliases(tenantRatingSubject engine.TenantRa
func (self *ApierV1) AddAccountAliases(attrs AttrAddAccountAliases, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"Tenant", "Account", "Aliases"}); len(missing) != 0 {
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
aliasesChanged := []string{}
for _, alias := range attrs.Aliases {
if err := self.AccountDb.SetAccAlias(utils.AccountAliasKey(attrs.Tenant, alias), attrs.Account); err != nil {
- return fmt.Errorf("%s:%s:%s", utils.ERR_SERVER_ERROR, alias, err.Error())
+ return utils.NewErrServerError(err)
}
aliasesChanged = append(aliasesChanged, engine.ACC_ALIAS_PREFIX+utils.AccountAliasKey(attrs.Tenant, alias))
}
didNotChange := []string{}
if err := self.AccountDb.CacheAccounting(didNotChange, didNotChange, aliasesChanged); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
*reply = utils.OK
return nil
@@ -109,12 +106,12 @@ func (self *ApierV1) AddAccountAliases(attrs AttrAddAccountAliases, reply *strin
// Retrieve aliases configured for an account
func (self *ApierV1) GetAccountAliases(attrs engine.TenantAccount, reply *[]string) error {
if missing := utils.MissingStructFields(&attrs, []string{"Tenant", "Account"}); len(missing) != 0 {
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if aliases, err := self.AccountDb.GetAccountAliases(attrs.Tenant, attrs.Account, false); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if len(aliases) == 0 {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
} else {
*reply = aliases
}
@@ -124,14 +121,14 @@ func (self *ApierV1) GetAccountAliases(attrs engine.TenantAccount, reply *[]stri
// Retrieve aliases configured for a rating profile subject
func (self *ApierV1) RemAccountAliases(tenantAccount engine.TenantAccount, reply *string) error {
if missing := utils.MissingStructFields(&tenantAccount, []string{"Tenant", "Account"}); len(missing) != 0 {
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if err := self.AccountDb.RemoveAccAliases([]*engine.TenantAccount{&tenantAccount}); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
didNotChange := []string{}
if err := self.AccountDb.CacheAccounting(didNotChange, didNotChange, nil); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
*reply = utils.OK
return nil
diff --git a/apier/v1/apier.go b/apier/v1/apier.go
index 2c105f9a2..95c195fe7 100644
--- a/apier/v1/apier.go
+++ b/apier/v1/apier.go
@@ -51,7 +51,7 @@ type ApierV1 struct {
func (self *ApierV1) GetDestination(dstId string, reply *engine.Destination) error {
if dst, err := self.RatingDb.GetDestination(dstId); err != nil {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
} else {
*reply = *dst
}
@@ -59,7 +59,7 @@ func (self *ApierV1) GetDestination(dstId string, reply *engine.Destination) err
}
func (apier *ApierV1) GetSharedGroup(sgId string, reply *engine.SharedGroup) error {
- if sg, err := apier.AccountDb.GetSharedGroup(sgId, false); err != nil && err.Error() != utils.ERR_NOT_FOUND { // Not found is not an error here
+ if sg, err := apier.AccountDb.GetSharedGroup(sgId, false); err != nil && err != utils.ErrNotFound { // Not found is not an error here
return err
} else {
if sg != nil {
@@ -77,7 +77,7 @@ type AttrSetDestination struct { //ToDo
func (self *ApierV1) GetRatingPlan(rplnId string, reply *engine.RatingPlan) error {
if rpln, err := self.RatingDb.GetRatingPlan(rplnId, false); err != nil {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
} else {
*reply = *rpln
}
@@ -187,13 +187,13 @@ type AttrLoadDestination struct {
// Load destinations from storDb into dataDb.
func (self *ApierV1) LoadDestination(attrs AttrLoadDestination, reply *string) error {
if len(attrs.TPid) == 0 {
- return fmt.Errorf("%s:%s", utils.ERR_MANDATORY_IE_MISSING, "TPid")
+ return utils.NewErrMandatoryIeMissing("TPid")
}
dbReader := engine.NewTpReader(self.RatingDb, self.AccountDb, self.StorDb, attrs.TPid)
if loaded, err := dbReader.LoadDestinationsFiltered(attrs.DestinationId); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if !loaded {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
}
//Automatic cache of the newly inserted rating plan
didNotChange := []string{}
@@ -211,12 +211,12 @@ func (self *ApierV1) LoadDestination(attrs AttrLoadDestination, reply *string) e
// Load derived chargers from storDb into dataDb.
func (self *ApierV1) LoadDerivedChargers(attrs utils.TPDerivedChargers, reply *string) error {
if len(attrs.TPid) == 0 {
- return fmt.Errorf("%s:%s", utils.ERR_MANDATORY_IE_MISSING, "TPid")
+ return utils.NewErrMandatoryIeMissing("TPid")
}
dbReader := engine.NewTpReader(self.RatingDb, self.AccountDb, self.StorDb, attrs.TPid)
dc := engine.APItoModelDerivedCharger(&attrs)
if err := dbReader.LoadDerivedChargersFiltered(&dc[0], true); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
//Automatic cache of the newly inserted rating plan
didNotChange := []string{}
@@ -239,13 +239,13 @@ type AttrLoadRatingPlan struct {
// Process dependencies and load a specific rating plan from storDb into dataDb.
func (self *ApierV1) LoadRatingPlan(attrs AttrLoadRatingPlan, reply *string) error {
if len(attrs.TPid) == 0 {
- return fmt.Errorf("%s:%s", utils.ERR_MANDATORY_IE_MISSING, "TPid")
+ return utils.NewErrMandatoryIeMissing("TPid")
}
dbReader := engine.NewTpReader(self.RatingDb, self.AccountDb, self.StorDb, attrs.TPid)
if loaded, err := dbReader.LoadRatingPlansFiltered(attrs.RatingPlanId); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if !loaded {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
}
//Automatic cache of the newly inserted rating plan
didNotChange := []string{}
@@ -263,12 +263,12 @@ func (self *ApierV1) LoadRatingPlan(attrs AttrLoadRatingPlan, reply *string) err
// Process dependencies and load a specific rating profile from storDb into dataDb.
func (self *ApierV1) LoadRatingProfile(attrs utils.TPRatingProfile, reply *string) error {
if len(attrs.TPid) == 0 {
- return fmt.Errorf("%s:%s", utils.ERR_MANDATORY_IE_MISSING, "TPid")
+ return utils.NewErrMandatoryIeMissing("TPid")
}
dbReader := engine.NewTpReader(self.RatingDb, self.AccountDb, self.StorDb, attrs.TPid)
rp := engine.APItoModelRatingProfile(&attrs)
if err := dbReader.LoadRatingProfilesFiltered(&rp[0]); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
//Automatic cache of the newly inserted rating profile
didNotChange := []string{}
@@ -291,11 +291,11 @@ type AttrLoadSharedGroup struct {
// Load destinations from storDb into dataDb.
func (self *ApierV1) LoadSharedGroup(attrs AttrLoadSharedGroup, reply *string) error {
if len(attrs.TPid) == 0 {
- return fmt.Errorf("%s:%s", utils.ERR_MANDATORY_IE_MISSING, "TPid")
+ return utils.NewErrMandatoryIeMissing("TPid")
}
dbReader := engine.NewTpReader(self.RatingDb, self.AccountDb, self.StorDb, attrs.TPid)
if err := dbReader.LoadSharedGroupsFiltered(attrs.SharedGroupId, true); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
//Automatic cache of the newly inserted rating plan
didNotChange := []string{}
@@ -318,11 +318,11 @@ type AttrLoadCdrStats struct {
// Load destinations from storDb into dataDb.
func (self *ApierV1) LoadCdrStats(attrs AttrLoadCdrStats, reply *string) error {
if len(attrs.TPid) == 0 {
- return fmt.Errorf("%s:%s", utils.ERR_MANDATORY_IE_MISSING, "TPid")
+ return utils.NewErrMandatoryIeMissing("TPid")
}
dbReader := engine.NewTpReader(self.RatingDb, self.AccountDb, self.StorDb, attrs.TPid)
if err := dbReader.LoadCdrStatsFiltered(attrs.CdrStatsId, true); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
*reply = OK
return nil
@@ -338,11 +338,11 @@ type AttrLoadTpFromStorDb struct {
// Loads complete data in a TP from storDb
func (self *ApierV1) LoadTariffPlanFromStorDb(attrs AttrLoadTpFromStorDb, reply *string) error {
if len(attrs.TPid) == 0 {
- return fmt.Errorf("%s:%s", utils.ERR_MANDATORY_IE_MISSING, "TPid")
+ return utils.NewErrMandatoryIeMissing("TPid")
}
dbReader := engine.NewTpReader(self.RatingDb, self.AccountDb, self.StorDb, attrs.TPid)
if err := dbReader.LoadAll(); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
if attrs.Validate {
if !dbReader.IsValid() {
@@ -355,7 +355,7 @@ func (self *ApierV1) LoadTariffPlanFromStorDb(attrs AttrLoadTpFromStorDb, reply
return nil // Mission complete, no errors
}
if err := dbReader.WriteToDatabase(attrs.FlushDb, false); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
// Make sure the items are in the cache
dstIds, _ := dbReader.GetLoadedIds(engine.DESTINATION_PREFIX)
@@ -435,18 +435,18 @@ type AttrImportTPFromFolder struct {
func (self *ApierV1) ImportTariffPlanFromFolder(attrs AttrImportTPFromFolder, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "FolderPath"}); len(missing) != 0 {
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if len(attrs.CsvSeparator) == 0 {
attrs.CsvSeparator = ","
}
if fi, err := os.Stat(attrs.FolderPath); err != nil {
if strings.HasSuffix(err.Error(), "no such file or directory") {
- return errors.New(utils.ERR_INVALID_PATH)
+ return utils.ErrInvalidPath
}
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if !fi.IsDir() {
- return errors.New(utils.ERR_INVALID_PATH)
+ return utils.ErrInvalidPath
}
csvImporter := engine.TPCSVImporter{
TPid: attrs.TPid,
@@ -457,7 +457,7 @@ func (self *ApierV1) ImportTariffPlanFromFolder(attrs AttrImportTPFromFolder, re
ImportId: attrs.RunId,
}
if err := csvImporter.Run(); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
*reply = utils.OK
return nil
@@ -475,38 +475,38 @@ type AttrSetRatingProfile struct {
// Sets a specific rating profile working with data directly in the RatingDb without involving storDb
func (self *ApierV1) SetRatingProfile(attrs AttrSetRatingProfile, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"Tenant", "TOR", "Direction", "Subject", "RatingPlanActivations"}); len(missing) != 0 {
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
for _, rpa := range attrs.RatingPlanActivations {
if missing := utils.MissingStructFields(rpa, []string{"ActivationTime", "RatingPlanId"}); len(missing) != 0 {
- return fmt.Errorf("%s:RatingPlanActivation:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return fmt.Errorf("%s:RatingPlanActivation:%v", utils.ErrMandatoryIeMissing.Error(), missing)
}
}
tpRpf := utils.TPRatingProfile{Tenant: attrs.Tenant, Category: attrs.Category, Direction: attrs.Direction, Subject: attrs.Subject}
keyId := tpRpf.KeyId()
if !attrs.Overwrite {
if exists, err := self.RatingDb.HasData(engine.RATING_PROFILE_PREFIX, keyId); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if exists {
- return errors.New(utils.ERR_EXISTS)
+ return utils.ErrExists
}
}
rpfl := &engine.RatingProfile{Id: keyId, RatingPlanActivations: make(engine.RatingPlanActivations, len(attrs.RatingPlanActivations))}
for idx, ra := range attrs.RatingPlanActivations {
at, err := utils.ParseDate(ra.ActivationTime)
if err != nil {
- return fmt.Errorf(fmt.Sprintf("%s:Cannot parse activation time from %v", utils.ERR_SERVER_ERROR, ra.ActivationTime))
+ return fmt.Errorf(fmt.Sprintf("%s:Cannot parse activation time from %v", utils.ErrServerError.Error(), ra.ActivationTime))
}
if exists, err := self.RatingDb.HasData(engine.RATING_PLAN_PREFIX, ra.RatingPlanId); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if !exists {
- return fmt.Errorf(fmt.Sprintf("%s:RatingPlanId:%s", utils.ERR_NOT_FOUND, ra.RatingPlanId))
+ return fmt.Errorf(fmt.Sprintf("%s:RatingPlanId:%s", utils.ErrNotFound.Error(), ra.RatingPlanId))
}
rpfl.RatingPlanActivations[idx] = &engine.RatingPlanActivation{ActivationTime: at, RatingPlanId: ra.RatingPlanId,
FallbackKeys: utils.FallbackSubjKeys(tpRpf.Direction, tpRpf.Tenant, tpRpf.Category, ra.FallbackSubjects)}
}
if err := self.RatingDb.SetRatingProfile(rpfl); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
//Automatic cache of the newly inserted rating profile
didNotChange := []string{}
@@ -519,7 +519,7 @@ func (self *ApierV1) SetRatingProfile(attrs AttrSetRatingProfile, reply *string)
func (self *ApierV1) SetActions(attrs utils.AttrSetActions, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"ActionsId", "Actions"}); len(missing) != 0 {
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
for _, action := range attrs.Actions {
requiredFields := []string{"Identifier", "Weight"}
@@ -527,14 +527,14 @@ func (self *ApierV1) SetActions(attrs utils.AttrSetActions, reply *string) error
requiredFields = append(requiredFields, "Direction", "Units")
}
if missing := utils.MissingStructFields(action, requiredFields); len(missing) != 0 {
- return fmt.Errorf("%s:Action:%s:%v", utils.ERR_MANDATORY_IE_MISSING, action.Identifier, missing)
+ return fmt.Errorf("%s:Action:%s:%v", utils.ErrMandatoryIeMissing.Error(), action.Identifier, missing)
}
}
if !attrs.Overwrite {
if exists, err := self.AccountDb.HasData(engine.ACTION_PREFIX, attrs.ActionsId); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if exists {
- return errors.New(utils.ERR_EXISTS)
+ return utils.ErrExists
}
}
storeActions := make(engine.Actions, len(attrs.Actions))
@@ -560,7 +560,7 @@ func (self *ApierV1) SetActions(attrs utils.AttrSetActions, reply *string) error
storeActions[idx] = a
}
if err := self.AccountDb.SetActions(attrs.ActionsId, storeActions); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
didNotChange := []string{}
self.AccountDb.CacheAccounting(nil, didNotChange, didNotChange)
@@ -571,12 +571,12 @@ func (self *ApierV1) SetActions(attrs utils.AttrSetActions, reply *string) error
// Retrieves actions attached to specific ActionsId within cache
func (self *ApierV1) GetActions(actsId string, reply *[]*utils.TPAction) error {
if len(actsId) == 0 {
- return fmt.Errorf("%s ActionsId: %s", utils.ERR_MANDATORY_IE_MISSING, actsId)
+ return fmt.Errorf("%s ActionsId: %s", utils.ErrMandatoryIeMissing.Error(), actsId)
}
acts := make([]*utils.TPAction, 0)
engActs, err := self.AccountDb.GetActions(actsId, false)
if err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
for _, engAct := range engActs {
act := &utils.TPAction{Identifier: engAct.ActionType,
@@ -618,27 +618,27 @@ type ApiActionPlan struct {
func (self *ApierV1) SetActionPlan(attrs AttrSetActionPlan, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"Id", "ActionPlan"}); len(missing) != 0 {
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
for _, at := range attrs.ActionPlan {
requiredFields := []string{"ActionsId", "Time", "Weight"}
if missing := utils.MissingStructFields(at, requiredFields); len(missing) != 0 {
- return fmt.Errorf("%s:Action:%s:%v", utils.ERR_MANDATORY_IE_MISSING, at.ActionsId, missing)
+ return fmt.Errorf("%s:Action:%s:%v", utils.ErrMandatoryIeMissing.Error(), at.ActionsId, missing)
}
}
if !attrs.Overwrite {
if exists, err := self.AccountDb.HasData(engine.ACTION_TIMING_PREFIX, attrs.Id); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if exists {
- return errors.New(utils.ERR_EXISTS)
+ return utils.ErrExists
}
}
storeAtms := make(engine.ActionPlans, len(attrs.ActionPlan))
for idx, apiAtm := range attrs.ActionPlan {
if exists, err := self.AccountDb.HasData(engine.ACTION_PREFIX, apiAtm.ActionsId); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if !exists {
- return fmt.Errorf("%s:%s", utils.ERR_BROKEN_REFERENCE, apiAtm.ActionsId)
+ return fmt.Errorf("%s:%s", utils.ErrBrokenReference.Error(), apiAtm.ActionsId)
}
timing := new(engine.RITiming)
timing.Years.Parse(apiAtm.Years, ";")
@@ -656,7 +656,7 @@ func (self *ApierV1) SetActionPlan(attrs AttrSetActionPlan, reply *string) error
storeAtms[idx] = at
}
if err := self.AccountDb.SetActionPlans(attrs.Id, storeAtms); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
if attrs.ReloadScheduler {
if self.Sched == nil {
@@ -693,7 +693,7 @@ func (self *ApierV1) AddTriggeredAction(attr AttrAddActionTrigger, reply *string
}
balExpiryTime, err := utils.ParseTimeDetectLayout(attr.BalanceExpiryTime)
if err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
at := &engine.ActionTrigger{
Id: attr.ActionTriggersId,
@@ -805,7 +805,7 @@ func (self *ApierV1) ResetTriggeredActions(attr AttrResetTriggeredAction, reply
// Process dependencies and load a specific AccountActions profile from storDb into dataDb.
func (self *ApierV1) LoadAccountActions(attrs utils.TPAccountActions, reply *string) error {
if len(attrs.TPid) == 0 {
- return fmt.Errorf("%s:%s", utils.ERR_MANDATORY_IE_MISSING, "TPid")
+ return utils.NewErrMandatoryIeMissing("TPid")
}
dbReader := engine.NewTpReader(self.RatingDb, self.AccountDb, self.StorDb, attrs.TPid)
if _, err := engine.AccLock.Guard(func() (interface{}, error) {
@@ -815,7 +815,7 @@ func (self *ApierV1) LoadAccountActions(attrs utils.TPAccountActions, reply *str
}
return 0, nil
}, attrs.KeyId()); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
// ToDo: Get the action keys loaded by dbReader so we reload only these in cache
// Need to do it before scheduler otherwise actions to run will be unknown
@@ -832,7 +832,7 @@ func (self *ApierV1) LoadAccountActions(attrs utils.TPAccountActions, reply *str
func (self *ApierV1) ReloadScheduler(input string, reply *string) error {
if self.Sched == nil {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
}
self.Sched.LoadActionPlans(self.AccountDb)
self.Sched.Restart()
@@ -925,7 +925,7 @@ func (self *ApierV1) GetCacheStats(attrs utils.AttrCacheStats, reply *utils.Cach
func (self *ApierV1) GetCachedItemAge(itemId string, reply *utils.CachedItemAge) error {
if len(itemId) == 0 {
- return fmt.Errorf("%s:ItemId", utils.ERR_MANDATORY_IE_MISSING)
+ return fmt.Errorf("%s:ItemId", utils.ErrMandatoryIeMissing.Error())
}
cachedItemAge := new(utils.CachedItemAge)
var found bool
@@ -955,7 +955,7 @@ func (self *ApierV1) GetCachedItemAge(itemId string, reply *utils.CachedItemAge)
}
}
if !found {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
}
*reply = *cachedItemAge
return nil
@@ -963,15 +963,15 @@ func (self *ApierV1) GetCachedItemAge(itemId string, reply *utils.CachedItemAge)
func (self *ApierV1) LoadTariffPlanFromFolder(attrs utils.AttrLoadTpFromFolder, reply *string) error {
if len(attrs.FolderPath) == 0 {
- return fmt.Errorf("%s:%s", utils.ERR_MANDATORY_IE_MISSING, "FolderPath")
+ return fmt.Errorf("%s:%s", utils.ErrMandatoryIeMissing.Error(), "FolderPath")
}
if fi, err := os.Stat(attrs.FolderPath); err != nil {
if strings.HasSuffix(err.Error(), "no such file or directory") {
- return errors.New(utils.ERR_INVALID_PATH)
+ return utils.ErrInvalidPath
}
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if !fi.IsDir() {
- return errors.New(utils.ERR_INVALID_PATH)
+ return utils.ErrInvalidPath
}
loader := engine.NewTpReader(self.RatingDb, self.AccountDb, engine.NewFileCSVStorage(utils.CSV_SEP,
path.Join(attrs.FolderPath, utils.DESTINATIONS_CSV),
@@ -989,7 +989,7 @@ func (self *ApierV1) LoadTariffPlanFromFolder(attrs utils.AttrLoadTpFromFolder,
path.Join(attrs.FolderPath, utils.DERIVED_CHARGERS_CSV),
path.Join(attrs.FolderPath, utils.CDR_STATS_CSV)), "")
if err := loader.LoadAll(); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
if attrs.DryRun {
*reply = OK
@@ -1004,7 +1004,7 @@ func (self *ApierV1) LoadTariffPlanFromFolder(attrs utils.AttrLoadTpFromFolder,
}
if err := loader.WriteToDatabase(attrs.FlushDb, false); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
// Make sure the items are in the cache
dstIds, _ := loader.GetLoadedIds(engine.DESTINATION_PREFIX)
diff --git a/apier/v1/apier_local_test.go b/apier/v1/apier_local_test.go
index 02c9581d5..280f7f608 100644
--- a/apier/v1/apier_local_test.go
+++ b/apier/v1/apier_local_test.go
@@ -1238,11 +1238,11 @@ func TestApierLoadTariffPlanFromFolder(t *testing.T) {
}
reply := ""
attrs := &utils.AttrLoadTpFromFolder{FolderPath: ""}
- if err := rater.Call("ApierV1.LoadTariffPlanFromFolder", attrs, &reply); err == nil || !strings.HasPrefix(err.Error(), utils.ERR_MANDATORY_IE_MISSING) {
+ if err := rater.Call("ApierV1.LoadTariffPlanFromFolder", attrs, &reply); err == nil || !strings.HasPrefix(err.Error(), utils.ErrMandatoryIeMissing.Error()) {
t.Error(err)
}
attrs = &utils.AttrLoadTpFromFolder{FolderPath: "/INVALID/"}
- if err := rater.Call("ApierV1.LoadTariffPlanFromFolder", attrs, &reply); err == nil || err.Error() != utils.ERR_INVALID_PATH {
+ if err := rater.Call("ApierV1.LoadTariffPlanFromFolder", attrs, &reply); err == nil || err.Error() != utils.ErrInvalidPath.Error() {
t.Error(err)
}
// Simple test that command is executed without errors
@@ -1332,8 +1332,8 @@ func TestApierGetCallCostLog(t *testing.T) {
}
attrs.CgrId = "dummyid"
attrs.RunId = "default"
- if err := rater.Call("ApierV1.GetCallCostLog", attrs, &cc); err == nil || err.Error() != "SERVER_ERROR:record not found" {
- t.Error("ApierV1.GetCallCostLog: should return NOT_FOUND, got: %v", err)
+ if err := rater.Call("ApierV1.GetCallCostLog", attrs, &cc); err == nil || err.Error() != "SERVER_ERROR: record not found" {
+ t.Error("ApierV1.GetCallCostLog: should return NOT_FOUND, got:", err)
}
}
@@ -1515,7 +1515,7 @@ func TestApierLocalGetRatingSubjectAliases(t *testing.T) {
var subjAliases []string
if err := rater.Call("ApierV1.GetRatingSubjectAliases", engine.TenantRatingSubject{Tenant: "cgrates.org", Subject: "1001"}, &subjAliases); err == nil {
t.Error("Unexpected nil error received")
- } else if err.Error() != utils.ERR_NOT_FOUND {
+ } else if err.Error() != utils.ErrNotFound.Error() {
t.Error("Unexpected error", err.Error())
}
}
@@ -1559,7 +1559,7 @@ func TestApierLocalRemRatingSubjectAliases(t *testing.T) {
var subjAliases []string
if err := rater.Call("ApierV1.GetRatingSubjectAliases", engine.TenantRatingSubject{Tenant: "cgrates.org", Subject: "1001"}, &subjAliases); err == nil {
t.Error("Unexpected nil error received")
- } else if err.Error() != utils.ERR_NOT_FOUND {
+ } else if err.Error() != utils.ErrNotFound.Error() {
t.Error("Unexpected error", err.Error())
}
}
@@ -1572,7 +1572,7 @@ func TestApierLocalGetAccountAliases(t *testing.T) {
var acntAliases []string
if err := rater.Call("ApierV1.GetAccountAliases", tenantAcnt, &acntAliases); err == nil {
t.Error("Unexpected nil error received")
- } else if err.Error() != utils.ERR_NOT_FOUND {
+ } else if err.Error() != utils.ErrNotFound.Error() {
t.Error("Unexpected error", err.Error())
}
}
@@ -1616,7 +1616,7 @@ func TestApierLocalRemAccountAliases(t *testing.T) {
var acntAliases []string
if err := rater.Call("ApierV1.GetAccountAliases", engine.TenantAccount{Tenant: "cgrates.org", Account: "1001"}, &acntAliases); err == nil {
t.Error("Unexpected nil error received")
- } else if err.Error() != utils.ERR_NOT_FOUND {
+ } else if err.Error() != utils.ErrNotFound.Error() {
t.Error("Unexpected error", err.Error())
}
}
diff --git a/apier/v1/callsetup.go b/apier/v1/callsetup.go
index 40c88e833..62e7a9115 100644
--- a/apier/v1/callsetup.go
+++ b/apier/v1/callsetup.go
@@ -19,7 +19,6 @@ along with this program. If not, see
package v1
import (
- "fmt"
"strconv"
"time"
@@ -58,7 +57,7 @@ func (self *ApierV1) GetMaxSessionTime(auth engine.MaxUsageReq, maxSessionTime *
}
storedCdr, err := auth.AsStoredCdr()
if err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
var maxDur float64
if err := self.Responder.GetDerivedMaxSessionTime(storedCdr, &maxDur); err != nil {
diff --git a/apier/v1/cdre.go b/apier/v1/cdre.go
index 0706f62bf..e5e93356f 100644
--- a/apier/v1/cdre.go
+++ b/apier/v1/cdre.go
@@ -96,24 +96,24 @@ func (self *ApierV1) ExportCdrsToFile(attr utils.AttrExpFileCdrs, reply *utils.E
if attr.ExportTemplate != nil && len(*attr.ExportTemplate) != 0 { // Export template prefered, use it
var hasIt bool
if exportTemplate, hasIt = self.Config.CdreProfiles[*attr.ExportTemplate]; !hasIt {
- return fmt.Errorf("%s:ExportTemplate", utils.ERR_NOT_FOUND)
+ return fmt.Errorf("%s:ExportTemplate", utils.ErrNotFound.Error())
}
}
if exportTemplate == nil {
- return fmt.Errorf("%s:ExportTemplate", utils.ERR_MANDATORY_IE_MISSING)
+ return fmt.Errorf("%s:ExportTemplate", utils.ErrMandatoryIeMissing.Error())
}
cdrFormat := exportTemplate.CdrFormat
if attr.CdrFormat != nil && len(*attr.CdrFormat) != 0 {
cdrFormat = strings.ToLower(*attr.CdrFormat)
}
if !utils.IsSliceMember(utils.CdreCdrFormats, cdrFormat) {
- return fmt.Errorf("%s:%s", utils.ERR_MANDATORY_IE_MISSING, "CdrFormat")
+ return fmt.Errorf("%s:%s", utils.ErrMandatoryIeMissing.Error(), "CdrFormat")
}
fieldSep := exportTemplate.FieldSeparator
if attr.FieldSeparator != nil && len(*attr.FieldSeparator) != 0 {
fieldSep, _ = utf8.DecodeRuneInString(*attr.FieldSeparator)
if fieldSep == utf8.RuneError {
- return fmt.Errorf("%s:FieldSeparator:%s", utils.ERR_SERVER_ERROR, "Invalid")
+ return fmt.Errorf("%s:FieldSeparator:%s", utils.ErrServerError.Error(), "Invalid")
}
}
exportDir := exportTemplate.ExportDir
@@ -166,7 +166,7 @@ func (self *ApierV1) ExportCdrsToFile(attr utils.AttrExpFileCdrs, reply *utils.E
}
cdrsFltr, err := attr.AsCdrsFilter()
if err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
cdrs, _, err := self.CdrDb.GetStoredCdrs(cdrsFltr)
if err != nil {
@@ -178,14 +178,14 @@ func (self *ApierV1) ExportCdrsToFile(attr utils.AttrExpFileCdrs, reply *utils.E
cdrexp, err := cdre.NewCdrExporter(cdrs, self.CdrDb, exportTemplate, cdrFormat, fieldSep, exportId, dataUsageMultiplyFactor, smsUsageMultiplyFactor, genericUsageMultiplyFactor,
costMultiplyFactor, costShiftDigits, roundingDecimals, self.Config.RoundingDecimals, maskDestId, maskLen, self.Config.HttpSkipTlsVerify)
if err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
if cdrexp.TotalExportedCdrs() == 0 {
*reply = utils.ExportedFileCdrs{ExportedFilePath: ""}
return nil
}
if err := cdrexp.WriteToFile(filePath); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
*reply = utils.ExportedFileCdrs{ExportedFilePath: filePath, TotalRecords: len(cdrs), TotalCost: cdrexp.TotalCost(), FirstOrderId: cdrexp.FirstOrderId(), LastOrderId: cdrexp.LastOrderId()}
if !attr.SuppressCgrIds {
@@ -198,10 +198,10 @@ func (self *ApierV1) ExportCdrsToFile(attr utils.AttrExpFileCdrs, reply *utils.E
// Remove Cdrs out of CDR storage
func (self *ApierV1) RemCdrs(attrs utils.AttrRemCdrs, reply *string) error {
if len(attrs.CgrIds) == 0 {
- return fmt.Errorf("%s:CgrIds", utils.ERR_MANDATORY_IE_MISSING)
+ return fmt.Errorf("%s:CgrIds", utils.ErrMandatoryIeMissing.Error())
}
if err := self.CdrDb.RemStoredCdrs(attrs.CgrIds); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
*reply = "OK"
return nil
diff --git a/apier/v1/cdrs.go b/apier/v1/cdrs.go
index b5b79346f..776fde7a4 100644
--- a/apier/v1/cdrs.go
+++ b/apier/v1/cdrs.go
@@ -19,8 +19,6 @@ along with this program. If not, see
package v1
import (
- "fmt"
-
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
@@ -33,12 +31,12 @@ type AttrGetCallCost struct {
// Retrieves the callCost out of CGR logDb
func (apier *ApierV1) GetCallCostLog(attrs AttrGetCallCost, reply *engine.CallCost) error {
if missing := utils.MissingStructFields(&attrs, []string{"CgrId", "RunId"}); len(missing) != 0 {
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if cc, err := apier.CdrDb.GetCallCostLog(attrs.CgrId, "", attrs.RunId); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if cc == nil {
- return fmt.Errorf("NOT_FOUND")
+ return utils.ErrNotFound
} else {
*reply = *cc
}
@@ -49,10 +47,10 @@ func (apier *ApierV1) GetCallCostLog(attrs AttrGetCallCost, reply *engine.CallCo
func (apier *ApierV1) GetCdrs(attrs utils.AttrGetCdrs, reply *[]*engine.ExternalCdr) error {
cdrsFltr, err := attrs.AsCdrsFilter()
if err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
if cdrs, _, err := apier.CdrDb.GetStoredCdrs(cdrsFltr); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if len(cdrs) == 0 {
*reply = make([]*engine.ExternalCdr, 0)
} else {
diff --git a/apier/v1/cdrstatsv1.go b/apier/v1/cdrstatsv1.go
index 9676d758a..adea8e0b1 100644
--- a/apier/v1/cdrstatsv1.go
+++ b/apier/v1/cdrstatsv1.go
@@ -36,7 +36,7 @@ type AttrGetMetrics struct {
func (sts *CDRStatsV1) GetMetrics(attr AttrGetMetrics, reply *map[string]float64) error {
if len(attr.StatsQueueId) == 0 {
- return fmt.Errorf("%s:StatsQueueId", utils.ERR_MANDATORY_IE_MISSING)
+ return fmt.Errorf("%s:StatsQueueId", utils.ErrMandatoryIeMissing.Error())
}
return sts.CdrStats.GetValues(attr.StatsQueueId, reply)
}
diff --git a/apier/v1/cdrsv1.go b/apier/v1/cdrsv1.go
index c3a4652ce..afa46d850 100644
--- a/apier/v1/cdrsv1.go
+++ b/apier/v1/cdrsv1.go
@@ -19,10 +19,10 @@ along with this program. If not, see
package v1
import (
- "fmt"
+ "time"
+
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
- "time"
)
// Receive CDRs via RPC methods
@@ -33,7 +33,7 @@ type CdrsV1 struct {
// Designed for CGR internal usage
func (self *CdrsV1) ProcessCdr(cdr *engine.StoredCdr, reply *string) error {
if err := self.CdrSrv.ProcessCdr(cdr); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
*reply = utils.OK
return nil
@@ -42,7 +42,7 @@ func (self *CdrsV1) ProcessCdr(cdr *engine.StoredCdr, reply *string) error {
// Designed for external programs feeding CDRs to CGRateS
func (self *CdrsV1) ProcessExternalCdr(cdr *engine.ExternalCdr, reply *string) error {
if err := self.CdrSrv.ProcessExternalCdr(cdr); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
*reply = utils.OK
return nil
@@ -67,7 +67,7 @@ func (self *CdrsV1) RateCdrs(attrs utils.AttrRateCdrs, reply *string) error {
if err := self.CdrSrv.RateCdrs(attrs.CgrIds, attrs.MediationRunIds, attrs.TORs, attrs.CdrHosts, attrs.CdrSources, attrs.ReqTypes, attrs.Directions,
attrs.Tenants, attrs.Categories, attrs.Accounts, attrs.Subjects, attrs.DestinationPrefixes, attrs.RatedAccounts, attrs.RatedSubjects,
attrs.OrderIdStart, attrs.OrderIdEnd, tStart, tEnd, attrs.RerateErrors, attrs.RerateRated, attrs.SendToStats); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
*reply = utils.OK
return nil
diff --git a/apier/v1/costs.go b/apier/v1/costs.go
index 8cf756d59..aaa856b73 100644
--- a/apier/v1/costs.go
+++ b/apier/v1/costs.go
@@ -19,7 +19,6 @@ along with this program. If not, see
package v1
import (
- "fmt"
"time"
"github.com/cgrates/cgrates/engine"
@@ -49,10 +48,10 @@ func (apier *ApierV1) GetDataCost(attrs AttrGetDataCost, reply *engine.DataCost)
}
var cc engine.CallCost
if err := apier.Responder.GetCost(cd, &cc); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
if dc, err := cc.ToDataCost(); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if dc != nil {
*reply = *dc
}
diff --git a/apier/v1/derivedcharging.go b/apier/v1/derivedcharging.go
index 41425346c..5d7647c25 100644
--- a/apier/v1/derivedcharging.go
+++ b/apier/v1/derivedcharging.go
@@ -28,10 +28,10 @@ import (
// Get DerivedChargers applying to our call, appends general configured to account specific ones if that is configured
func (self *ApierV1) GetDerivedChargers(attrs utils.AttrDerivedChargers, reply *utils.DerivedChargers) (err error) {
if missing := utils.MissingStructFields(&attrs, []string{"Tenant", "Direction", "Account", "Subject"}); len(missing) != 0 {
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if hDc, err := engine.HandleGetDerivedChargers(self.RatingDb, &attrs); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if hDc != nil {
*reply = hDc
}
@@ -61,15 +61,15 @@ func (self *ApierV1) SetDerivedChargers(attrs AttrSetDerivedChargers, reply *str
}
for _, dc := range attrs.DerivedChargers {
if _, err = utils.ParseRSRFields(dc.RunFilters, utils.INFIELD_SEP); err != nil { // Make sure rules are OK before loading in db
- return fmt.Errorf("%s:%s", utils.ERR_PARSER_ERROR, err.Error())
+ return fmt.Errorf("%s:%s", utils.ErrParserError.Error(), err.Error())
}
}
dcKey := utils.DerivedChargersKey(attrs.Direction, attrs.Tenant, attrs.Category, attrs.Account, attrs.Subject)
if err := self.RatingDb.SetDerivedChargers(dcKey, attrs.DerivedChargers); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
if err := self.RatingDb.CacheRating([]string{}, []string{}, []string{}, []string{}, []string{}, []string{engine.DERIVEDCHARGERS_PREFIX + dcKey}); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
*reply = utils.OK
return nil
@@ -96,12 +96,12 @@ func (self *ApierV1) RemDerivedChargers(attrs AttrRemDerivedChargers, reply *str
attrs.Subject = utils.ANY
}
if err := self.RatingDb.SetDerivedChargers(utils.DerivedChargersKey(attrs.Direction, attrs.Tenant, attrs.Category, attrs.Account, attrs.Subject), nil); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else {
*reply = "OK"
}
if err := self.RatingDb.CacheRating([]string{}, []string{}, []string{}, []string{}, []string{}, nil); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
return nil
}
diff --git a/apier/v1/lcr.go b/apier/v1/lcr.go
index 98b979809..a5beb1e9b 100644
--- a/apier/v1/lcr.go
+++ b/apier/v1/lcr.go
@@ -19,7 +19,6 @@ along with this program. If not, see
package v1
import (
- "errors"
"fmt"
"github.com/cgrates/cgrates/engine"
@@ -34,21 +33,21 @@ func (self *ApierV1) GetLcr(lcrReq engine.LcrRequest, lcrReply *engine.LcrReply)
}
var lcrQried engine.LCRCost
if err := self.Responder.GetLCR(cd, &lcrQried); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
if lcrQried.Entry == nil {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
}
if lcrQried.HasErrors() {
lcrQried.LogErrors()
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, "LCR_COMPUTE_ERRORS")
+ return fmt.Errorf("%s:%s", utils.ErrServerError.Error(), "LCR_COMPUTE_ERRORS")
}
lcrReply.DestinationId = lcrQried.Entry.DestinationId
lcrReply.RPCategory = lcrQried.Entry.RPCategory
lcrReply.Strategy = lcrQried.Entry.Strategy
for _, qriedSuppl := range lcrQried.SupplierCosts {
if dtcs, err := utils.NewDTCSFromRPKey(qriedSuppl.Supplier); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else {
lcrReply.Suppliers = append(lcrReply.Suppliers, &engine.LcrSupplier{Supplier: dtcs.Subject, Cost: qriedSuppl.Cost, QOS: qriedSuppl.QOS})
}
@@ -64,14 +63,14 @@ func (self *ApierV1) GetLcrSuppliers(lcrReq engine.LcrRequest, suppliers *string
}
var lcrQried engine.LCRCost
if err := self.Responder.GetLCR(cd, &lcrQried); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
if lcrQried.HasErrors() {
lcrQried.LogErrors()
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, "LCR_ERRORS")
+ return fmt.Errorf("%s:%s", utils.ErrServerError.Error(), "LCR_ERRORS")
}
if suppliersStr, err := lcrQried.SuppliersString(); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else {
*suppliers = suppliersStr
}
diff --git a/apier/v1/tp.go b/apier/v1/tp.go
index c5bf47512..4934ff2b6 100644
--- a/apier/v1/tp.go
+++ b/apier/v1/tp.go
@@ -21,8 +21,6 @@ package v1
// Tariff plan related APIs
import (
- "errors"
- "fmt"
"io/ioutil"
"os"
"path/filepath"
@@ -37,9 +35,9 @@ type AttrGetTPIds struct {
// Queries tarrif plan identities gathered from all tables.
func (self *ApierV1) GetTPIds(attrs AttrGetTPIds, reply *[]string) error {
if ids, err := self.StorDb.GetTpIds(); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if ids == nil {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
} else {
*reply = ids
}
diff --git a/apier/v1/tpaccountactions.go b/apier/v1/tpaccountactions.go
index 4f3402a41..56778e3d8 100644
--- a/apier/v1/tpaccountactions.go
+++ b/apier/v1/tpaccountactions.go
@@ -19,9 +19,6 @@ along with this program. If not, see
package v1
import (
- "errors"
- "fmt"
-
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
@@ -30,11 +27,11 @@ import (
func (self *ApierV1) SetTPAccountActions(attrs utils.TPAccountActions, reply *string) error {
if missing := utils.MissingStructFields(&attrs,
[]string{"TPid", "LoadId", "Tenant", "Account", "Direction", "ActionPlanId", "ActionTriggersId"}); len(missing) != 0 {
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
aas := engine.APItoModelAccountAction(&attrs)
if err := self.StorDb.SetTpAccountActions([]engine.TpAccountAction{*aas}); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
*reply = "OK"
return nil
@@ -52,13 +49,13 @@ func (self *ApierV1) GetTPAccountActionsByLoadId(attrs utils.TPAccountActions, r
mndtryFlds = append(mndtryFlds, "Tenant", "Account", "Direction")
}
if missing := utils.MissingStructFields(&attrs, mndtryFlds); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
aas := engine.APItoModelAccountAction(&attrs)
if aa, err := self.StorDb.GetTpAccountActions(aas); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if len(aa) == 0 {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
} else {
tpAa, err := engine.TpAccountActions(aa).GetAccountActions()
@@ -86,7 +83,7 @@ type AttrGetTPAccountActions struct {
// Queries specific DerivedCharge on tariff plan
func (self *ApierV1) GetTPAccountActions(attrs AttrGetTPAccountActions, reply *utils.TPAccountActions) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "AccountActionsId"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
tmpAa := &utils.TPAccountActions{TPid: attrs.TPid}
if err := tmpAa.SetAccountActionsId(attrs.AccountActionsId); err != nil {
@@ -94,9 +91,9 @@ func (self *ApierV1) GetTPAccountActions(attrs AttrGetTPAccountActions, reply *u
}
tmpAaa := engine.APItoModelAccountAction(tmpAa)
if aas, err := self.StorDb.GetTpAccountActions(tmpAaa); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if len(aas) == 0 {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
} else {
tpAaa, err := engine.TpAccountActions(aas).GetAccountActions()
if err != nil {
@@ -124,12 +121,12 @@ type AttrGetTPAccountActionIds struct {
// Queries AccountActions identities on specific tariff plan.
func (self *ApierV1) GetTPAccountActionLoadIds(attrs AttrGetTPAccountActionIds, reply *[]string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBL_TP_ACCOUNT_ACTIONS, utils.TPDistinctIds{"loadid"}, nil, &attrs.Paginator); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if ids == nil {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
} else {
*reply = ids
}
@@ -139,12 +136,12 @@ func (self *ApierV1) GetTPAccountActionLoadIds(attrs AttrGetTPAccountActionIds,
// Queries DerivedCharges identities on specific tariff plan.
func (self *ApierV1) GetTPAccountActionIds(attrs AttrGetTPAccountActionIds, reply *[]string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBL_TP_ACCOUNT_ACTIONS, utils.TPDistinctIds{"loadid", "direction", "tenant", "account"}, nil, &attrs.Paginator); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if ids == nil {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
} else {
*reply = ids
}
@@ -154,14 +151,14 @@ func (self *ApierV1) GetTPAccountActionIds(attrs AttrGetTPAccountActionIds, repl
// Removes specific AccountActions on Tariff plan
func (self *ApierV1) RemTPAccountActions(attrs AttrGetTPAccountActions, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "LoadId", "Tenant", "Account", "Direction"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
aa := engine.TpAccountAction{Tpid: attrs.TPid}
if err := aa.SetAccountActionId(attrs.AccountActionsId); err != nil {
return err
}
if err := self.StorDb.RemTpData(utils.TBL_TP_ACCOUNT_ACTIONS, aa.Tpid, aa.Loadid, aa.Direction, aa.Tenant, aa.Account); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else {
*reply = "OK"
}
diff --git a/apier/v1/tpactionplans.go b/apier/v1/tpactionplans.go
index a96f87c9d..4824c9794 100644
--- a/apier/v1/tpactionplans.go
+++ b/apier/v1/tpactionplans.go
@@ -19,7 +19,6 @@ along with this program. If not, see
package v1
import (
- "errors"
"fmt"
"github.com/cgrates/cgrates/engine"
@@ -29,17 +28,17 @@ import (
// Creates a new ActionTimings profile within a tariff plan
func (self *ApierV1) SetTPActionPlan(attrs utils.TPActionPlan, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ActionPlanId", "ActionPlan"}); len(missing) != 0 {
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
for _, at := range attrs.ActionPlan {
requiredFields := []string{"ActionsId", "TimingId", "Weight"}
if missing := utils.MissingStructFields(at, requiredFields); len(missing) != 0 {
- return fmt.Errorf("%s:Action:%s:%v", utils.ERR_MANDATORY_IE_MISSING, at.ActionsId, missing)
+ return fmt.Errorf("%s:Action:%s:%v", utils.ErrMandatoryIeMissing.Error(), at.ActionsId, missing)
}
}
ap := engine.APItoModelActionPlan(&attrs)
if err := self.StorDb.SetTpActionPlans(ap); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
*reply = "OK"
return nil
@@ -53,12 +52,12 @@ type AttrGetTPActionPlan struct {
// Queries specific ActionPlan profile on tariff plan
func (self *ApierV1) GetTPActionPlan(attrs AttrGetTPActionPlan, reply *utils.TPActionPlan) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "Id"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if ats, err := self.StorDb.GetTpActionPlans(attrs.TPid, attrs.Id); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if len(ats) == 0 {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
} else { // Got the data we need, convert it
aps, err := engine.TpActionPlans(ats).GetActionPlans()
if err != nil {
@@ -82,12 +81,12 @@ type AttrGetTPActionPlanIds struct {
// Queries ActionPlan identities on specific tariff plan.
func (self *ApierV1) GetTPActionPlanIds(attrs AttrGetTPActionPlanIds, reply *[]string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBL_TP_ACTION_PLANS, utils.TPDistinctIds{"tag"}, nil, &attrs.Paginator); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if ids == nil {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
} else {
*reply = ids
}
@@ -97,10 +96,10 @@ func (self *ApierV1) GetTPActionPlanIds(attrs AttrGetTPActionPlanIds, reply *[]s
// Removes specific ActionPlan on Tariff plan
func (self *ApierV1) RemTPActionPlan(attrs AttrGetTPActionPlan, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "Id"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if err := self.StorDb.RemTpData(utils.TBL_TP_ACTION_PLANS, attrs.TPid, attrs.Id); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else {
*reply = "OK"
}
diff --git a/apier/v1/tpactions.go b/apier/v1/tpactions.go
index 700ab135f..1d53915fe 100644
--- a/apier/v1/tpactions.go
+++ b/apier/v1/tpactions.go
@@ -19,7 +19,6 @@ along with this program. If not, see
package v1
import (
- "errors"
"fmt"
"github.com/cgrates/cgrates/engine"
@@ -29,7 +28,7 @@ import (
// Creates a new Actions profile within a tariff plan
func (self *ApierV1) SetTPActions(attrs utils.TPActions, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ActionsId", "Actions"}); len(missing) != 0 {
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
for _, action := range attrs.Actions {
requiredFields := []string{"Identifier", "Weight"}
@@ -37,12 +36,12 @@ func (self *ApierV1) SetTPActions(attrs utils.TPActions, reply *string) error {
requiredFields = append(requiredFields, "Direction", "Units")
}
if missing := utils.MissingStructFields(action, requiredFields); len(missing) != 0 {
- return fmt.Errorf("%s:Action:%s:%v", utils.ERR_MANDATORY_IE_MISSING, action.Identifier, missing)
+ return fmt.Errorf("%s:Action:%s:%v", utils.ErrMandatoryIeMissing.Error(), action.Identifier, missing)
}
}
as := engine.APItoModelAction(&attrs)
if err := self.StorDb.SetTpActions(as); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
*reply = "OK"
return nil
@@ -56,12 +55,12 @@ type AttrGetTPActions struct {
// Queries specific Actions profile on tariff plan
func (self *ApierV1) GetTPActions(attrs AttrGetTPActions, reply *utils.TPActions) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ActionsId"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if acts, err := self.StorDb.GetTpActions(attrs.TPid, attrs.ActionsId); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if len(acts) == 0 {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
} else {
as, err := engine.TpActions(acts).GetActions()
if err != nil {
@@ -80,12 +79,12 @@ type AttrGetTPActionIds struct {
// Queries Actions identities on specific tariff plan.
func (self *ApierV1) GetTPActionIds(attrs AttrGetTPActionIds, reply *[]string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBL_TP_ACTIONS, utils.TPDistinctIds{"tag"}, nil, &attrs.Paginator); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if ids == nil {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
} else {
*reply = ids
}
@@ -95,10 +94,10 @@ func (self *ApierV1) GetTPActionIds(attrs AttrGetTPActionIds, reply *[]string) e
// Removes specific Actions on Tariff plan
func (self *ApierV1) RemTPActions(attrs AttrGetTPActions, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ActionsId"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if err := self.StorDb.RemTpData(utils.TBL_TP_ACTIONS, attrs.TPid, attrs.ActionsId); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else {
*reply = "OK"
}
diff --git a/apier/v1/tpactiontriggers.go b/apier/v1/tpactiontriggers.go
index a32169d98..19447a849 100644
--- a/apier/v1/tpactiontriggers.go
+++ b/apier/v1/tpactiontriggers.go
@@ -19,9 +19,6 @@ along with this program. If not, see
package v1
import (
- "errors"
- "fmt"
-
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
@@ -30,12 +27,12 @@ import (
func (self *ApierV1) SetTPActionTriggers(attrs utils.TPActionTriggers, reply *string) error {
if missing := utils.MissingStructFields(&attrs,
[]string{"TPid", "ActionTriggersId"}); len(missing) != 0 {
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
ats := engine.APItoModelActionTrigger(&attrs)
if err := self.StorDb.SetTpActionTriggers(ats); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
*reply = "OK"
return nil
@@ -49,12 +46,12 @@ type AttrGetTPActionTriggers struct {
// Queries specific ActionTriggers profile on tariff plan
func (self *ApierV1) GetTPActionTriggers(attrs AttrGetTPActionTriggers, reply *utils.TPActionTriggers) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ActionTriggersId"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if ats, err := self.StorDb.GetTpActionTriggers(attrs.TPid, attrs.ActionTriggersId); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if len(ats) == 0 {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
} else {
atsMap, err := engine.TpActionTriggers(ats).GetActionTriggers()
if err != nil {
@@ -78,12 +75,12 @@ type AttrGetTPActionTriggerIds struct {
// Queries ActionTriggers identities on specific tariff plan.
func (self *ApierV1) GetTPActionTriggerIds(attrs AttrGetTPActionTriggerIds, reply *[]string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBL_TP_ACTION_TRIGGERS, utils.TPDistinctIds{"tag"}, nil, &attrs.Paginator); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if ids == nil {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
} else {
*reply = ids
}
@@ -93,10 +90,10 @@ func (self *ApierV1) GetTPActionTriggerIds(attrs AttrGetTPActionTriggerIds, repl
// Removes specific ActionTriggers on Tariff plan
func (self *ApierV1) RemTPActionTriggers(attrs AttrGetTPActionTriggers, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ActionTriggersId"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if err := self.StorDb.RemTpData(utils.TBL_TP_ACTION_TRIGGERS, attrs.TPid, attrs.ActionTriggersId); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else {
*reply = "OK"
}
diff --git a/apier/v1/tpcdrstats.go b/apier/v1/tpcdrstats.go
index 62e04a2bb..9990cc139 100644
--- a/apier/v1/tpcdrstats.go
+++ b/apier/v1/tpcdrstats.go
@@ -19,9 +19,6 @@ along with this program. If not, see
package v1
import (
- "errors"
- "fmt"
-
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
@@ -29,7 +26,7 @@ import (
// Creates a new CdrStats profile within a tariff plan
func (self *ApierV1) SetTPCdrStats(attrs utils.TPCdrStats, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "CdrStatsId", "CdrStats"}); len(missing) != 0 {
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
/*for _, action := range attrs.CdrStats {
requiredFields := []string{"Identifier", "Weight"}
@@ -42,7 +39,7 @@ func (self *ApierV1) SetTPCdrStats(attrs utils.TPCdrStats, reply *string) error
}*/
cs := engine.APItoModelCdrStat(&attrs)
if err := self.StorDb.SetTpCdrStats(cs); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
*reply = "OK"
return nil
@@ -56,12 +53,12 @@ type AttrGetTPCdrStats struct {
// Queries specific CdrStat on tariff plan
func (self *ApierV1) GetTPCdrStats(attrs AttrGetTPCdrStats, reply *utils.TPCdrStats) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "CdrStatsId"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if sgs, err := self.StorDb.GetTpCdrStats(attrs.TPid, attrs.CdrStatsId); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if len(sgs) == 0 {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
} else {
csMap, err := engine.TpCdrStats(sgs).GetCdrStats()
if err != nil {
@@ -80,12 +77,12 @@ type AttrGetTPCdrStatIds struct {
// Queries CdrStats identities on specific tariff plan.
func (self *ApierV1) GetTPCdrStatsIds(attrs AttrGetTPCdrStatIds, reply *[]string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBL_TP_CDR_STATS, utils.TPDistinctIds{"tag"}, nil, &attrs.Paginator); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if ids == nil {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
} else {
*reply = ids
}
@@ -95,10 +92,10 @@ func (self *ApierV1) GetTPCdrStatsIds(attrs AttrGetTPCdrStatIds, reply *[]string
// Removes specific CdrStats on Tariff plan
func (self *ApierV1) RemTPCdrStats(attrs AttrGetTPCdrStats, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "CdrStatsId"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if err := self.StorDb.RemTpData(utils.TBL_TP_SHARED_GROUPS, attrs.TPid, attrs.CdrStatsId); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else {
*reply = "OK"
}
diff --git a/apier/v1/tpderivedcharges.go b/apier/v1/tpderivedcharges.go
index dfb376b37..85b608581 100644
--- a/apier/v1/tpderivedcharges.go
+++ b/apier/v1/tpderivedcharges.go
@@ -19,9 +19,6 @@ along with this program. If not, see
package v1
import (
- "errors"
- "fmt"
-
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
@@ -29,7 +26,7 @@ import (
// Creates a new DerivedCharges profile within a tariff plan
func (self *ApierV1) SetTPDerivedChargers(attrs utils.TPDerivedChargers, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "Direction", "Tenant", "Category", "Account", "Subject"}); len(missing) != 0 {
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
/*for _, action := range attrs.DerivedCharges {
requiredFields := []string{"Identifier", "Weight"}
@@ -42,7 +39,7 @@ func (self *ApierV1) SetTPDerivedChargers(attrs utils.TPDerivedChargers, reply *
}*/
dc := engine.APItoModelDerivedCharger(&attrs)
if err := self.StorDb.SetTpDerivedChargers(dc); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
*reply = "OK"
return nil
@@ -56,7 +53,7 @@ type AttrGetTPDerivedChargers struct {
// Queries specific DerivedCharge on tariff plan
func (self *ApierV1) GetTPDerivedChargers(attrs AttrGetTPDerivedChargers, reply *utils.TPDerivedChargers) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "DerivedChargersId"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
tmpDc := &utils.TPDerivedChargers{TPid: attrs.TPid}
if err := tmpDc.SetDerivedChargersId(attrs.DerivedChargersId); err != nil {
@@ -64,9 +61,9 @@ func (self *ApierV1) GetTPDerivedChargers(attrs AttrGetTPDerivedChargers, reply
}
dcs := engine.APItoModelDerivedCharger(tmpDc)
if sgs, err := self.StorDb.GetTpDerivedChargers(&dcs[0]); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if len(sgs) == 0 {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
} else {
dcsMap, err := engine.TpDerivedChargers(dcs).GetDerivedChargers()
if err != nil {
@@ -85,12 +82,12 @@ type AttrGetTPDerivedChargeIds struct {
// Queries DerivedCharges identities on specific tariff plan.
func (self *ApierV1) GetTPDerivedChargerIds(attrs AttrGetTPDerivedChargeIds, reply *[]string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBL_TP_DERIVED_CHARGERS, utils.TPDistinctIds{"loadid", "direction", "tenant", "category", "account", "subject"}, nil, &attrs.Paginator); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if ids == nil {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
} else {
*reply = ids
}
@@ -100,14 +97,14 @@ func (self *ApierV1) GetTPDerivedChargerIds(attrs AttrGetTPDerivedChargeIds, rep
// Removes specific DerivedCharges on Tariff plan
func (self *ApierV1) RemTPDerivedChargers(attrs AttrGetTPDerivedChargers, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "DerivedChargesId"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
tmpDc := engine.TpDerivedCharger{}
if err := tmpDc.SetDerivedChargersId(attrs.DerivedChargersId); err != nil {
return err
}
if err := self.StorDb.RemTpData(utils.TBL_TP_DERIVED_CHARGERS, attrs.TPid, tmpDc.Loadid, tmpDc.Direction, tmpDc.Tenant, tmpDc.Category, tmpDc.Account, tmpDc.Subject); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else {
*reply = "OK"
}
diff --git a/apier/v1/tpdestinationrates.go b/apier/v1/tpdestinationrates.go
index 2c023ae88..1fa003b40 100644
--- a/apier/v1/tpdestinationrates.go
+++ b/apier/v1/tpdestinationrates.go
@@ -21,9 +21,6 @@ package v1
// This file deals with tp_destination_rates management over APIs
import (
- "errors"
- "fmt"
-
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
@@ -31,11 +28,11 @@ import (
// Creates a new DestinationRate profile within a tariff plan
func (self *ApierV1) SetTPDestinationRate(attrs utils.TPDestinationRate, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "DestinationRateId", "DestinationRates"}); len(missing) != 0 {
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
drs := engine.APItoModelDestinationRate(&attrs)
if err := self.StorDb.SetTpDestinationRates(drs); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
*reply = "OK"
return nil
@@ -50,12 +47,12 @@ type AttrGetTPDestinationRate struct {
// Queries specific DestinationRate profile on tariff plan
func (self *ApierV1) GetTPDestinationRate(attrs AttrGetTPDestinationRate, reply *utils.TPDestinationRate) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "DestinationRateId"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if drs, err := self.StorDb.GetTpDestinationRates(attrs.TPid, attrs.DestinationRateId, &attrs.Paginator); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if len(drs) == 0 {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
} else {
drsMap, err := engine.TpDestinationRates(drs).GetDestinationRates()
if err != nil {
@@ -74,12 +71,12 @@ type AttrTPDestinationRateIds struct {
// Queries DestinationRate identities on specific tariff plan.
func (self *ApierV1) GetTPDestinationRateIds(attrs AttrGetTPRateIds, reply *[]string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBL_TP_DESTINATION_RATES, utils.TPDistinctIds{"tag"}, nil, &attrs.Paginator); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if ids == nil {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
} else {
*reply = ids
}
@@ -89,10 +86,10 @@ func (self *ApierV1) GetTPDestinationRateIds(attrs AttrGetTPRateIds, reply *[]st
// Removes specific DestinationRate on Tariff plan
func (self *ApierV1) RemTPDestinationRate(attrs AttrGetTPDestinationRate, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "DestinationRateId"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if err := self.StorDb.RemTpData(utils.TBL_TP_DESTINATION_RATES, attrs.TPid, attrs.DestinationRateId); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else {
*reply = "OK"
}
diff --git a/apier/v1/tpdestinations.go b/apier/v1/tpdestinations.go
index a83610b96..a6f68fbeb 100644
--- a/apier/v1/tpdestinations.go
+++ b/apier/v1/tpdestinations.go
@@ -19,9 +19,6 @@ along with this program. If not, see
package v1
import (
- "errors"
- "fmt"
-
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
@@ -29,11 +26,11 @@ import (
// Creates a new destination within a tariff plan
func (self *ApierV1) SetTPDestination(attrs utils.TPDestination, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "DestinationId", "Prefixes"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
ds := engine.APItoModelDestination(&attrs)
if err := self.StorDb.SetTpDestinations(ds); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
*reply = "OK"
return nil
@@ -47,13 +44,13 @@ type AttrGetTPDestination struct {
// Queries a specific destination
func (self *ApierV1) GetTPDestination(attrs AttrGetTPDestination, reply *utils.TPDestination) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "DestinationId"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if storData, err := self.StorDb.GetTpDestinations(attrs.TPid, attrs.DestinationId); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if len(storData) == 0 {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
} else {
dsts, err := engine.TpDestinations(storData).GetDestinations()
if err != nil {
@@ -75,12 +72,12 @@ type AttrGetTPDestinationIds struct {
// Queries destination identities on specific tariff plan.
func (self *ApierV1) GetTPDestinationIds(attrs AttrGetTPDestinationIds, reply *[]string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBL_TP_DESTINATIONS, utils.TPDistinctIds{"tag"}, nil, &attrs.Paginator); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if ids == nil {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
} else {
*reply = ids
}
@@ -89,10 +86,10 @@ func (self *ApierV1) GetTPDestinationIds(attrs AttrGetTPDestinationIds, reply *[
func (self *ApierV1) RemTPDestination(attrs AttrGetTPDestination, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "DestinationId"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if err := self.StorDb.RemTpData(utils.TBL_TP_DESTINATIONS, attrs.TPid, attrs.DestinationId); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else {
*reply = "OK"
}
diff --git a/apier/v1/tplcrrules.go b/apier/v1/tplcrrules.go
index 3e9ca6a59..009480cf5 100644
--- a/apier/v1/tplcrrules.go
+++ b/apier/v1/tplcrrules.go
@@ -22,7 +22,7 @@ package v1
// Creates a new LcrRules profile within a tariff plan
func (self *ApierV1) SetTPLcrRules(attrs utils.TPLcrRules, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "LcrRulesId", "LcrRules"}); len(missing) != 0 {
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
for _, action := range attrs.LcrRules {
requiredFields := []string{"Identifier", "Weight"}
@@ -32,7 +32,7 @@ func (self *ApierV1) SetTPLcrRules(attrs utils.TPLcrRules, reply *string) error
}
}
if err := self.StorDb.SetTPLcrRules(attrs.TPid, map[string][]*utils.TPLcrRule{attrs.LcrRulesId: attrs.LcrRules}); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
*reply = "OK"
return nil
@@ -46,12 +46,12 @@ type AttrGetTPLcrRules struct {
// Queries specific LcrRules profile on tariff plan
func (self *ApierV1) GetTPLcrRules(attrs AttrGetTPLcrRules, reply *utils.TPLcrRules) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "LcrId"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if lcrs, err := self.StorDb.GetTpLCRs(attrs.TPid, attrs.LcrId); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if len(acts) == 0 {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
} else {
*reply = utils.TPLcrRules{TPid: attrs.TPid, LcrRulesId: attrs.LcrRulesId, LcrRules: lcrs[attrs.LcrRulesId]}
}
@@ -65,12 +65,12 @@ type AttrGetTPLcrActionIds struct {
// Queries LcrRules identities on specific tariff plan.
func (self *ApierV1) GetTPLcrActionIds(attrs AttrGetTPLcrActionIds, reply *[]string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if ids, err := self.StorDb.GetTPTableIds(attrs.TPid, utils.TBL_TP_LCRS, "id", nil); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if ids == nil {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
} else {
*reply = ids
}
@@ -80,10 +80,10 @@ func (self *ApierV1) GetTPLcrActionIds(attrs AttrGetTPLcrActionIds, reply *[]str
// Removes specific LcrRules on Tariff plan
func (self *ApierV1) RemTPLcrRules(attrs AttrGetTPLcrRules, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "LcrRulesId"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if err := self.StorDb.RemTPData(utils.TBL_TP_LCRS, attrs.TPid, attrs.LcrRulesId); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else {
*reply = "OK"
}
diff --git a/apier/v1/tprates.go b/apier/v1/tprates.go
index 96749921d..64de7d1d4 100644
--- a/apier/v1/tprates.go
+++ b/apier/v1/tprates.go
@@ -21,9 +21,6 @@ package v1
// This file deals with tp_rates management over APIs
import (
- "errors"
- "fmt"
-
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
@@ -31,11 +28,11 @@ import (
// Creates a new rate within a tariff plan
func (self *ApierV1) SetTPRate(attrs utils.TPRate, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "RateId", "RateSlots"}); len(missing) != 0 {
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
r := engine.APItoModelRate(&attrs)
if err := self.StorDb.SetTpRates(r); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
*reply = "OK"
return nil
@@ -49,12 +46,12 @@ type AttrGetTPRate struct {
// Queries specific Rate on tariff plan
func (self *ApierV1) GetTPRate(attrs AttrGetTPRate, reply *utils.TPRate) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "RateId"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if rts, err := self.StorDb.GetTpRates(attrs.TPid, attrs.RateId); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if len(rts) == 0 {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
} else {
rtsMap, err := engine.TpRates(rts).GetRates()
if err != nil {
@@ -73,12 +70,12 @@ type AttrGetTPRateIds struct {
// Queries rate identities on specific tariff plan.
func (self *ApierV1) GetTPRateIds(attrs AttrGetTPRateIds, reply *[]string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBL_TP_RATES, utils.TPDistinctIds{"tag"}, nil, &attrs.Paginator); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if ids == nil {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
} else {
*reply = ids
}
@@ -88,10 +85,10 @@ func (self *ApierV1) GetTPRateIds(attrs AttrGetTPRateIds, reply *[]string) error
// Removes specific Rate on Tariff plan
func (self *ApierV1) RemTPRate(attrs AttrGetTPRate, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "RateId"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if err := self.StorDb.RemTpData(utils.TBL_TP_RATES, attrs.TPid, attrs.RateId); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else {
*reply = "OK"
}
diff --git a/apier/v1/tpratingplans.go b/apier/v1/tpratingplans.go
index 050d26c81..6bcdd0196 100644
--- a/apier/v1/tpratingplans.go
+++ b/apier/v1/tpratingplans.go
@@ -21,9 +21,6 @@ package v1
// This file deals with tp_destrates_timing management over APIs
import (
- "errors"
- "fmt"
-
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
@@ -31,11 +28,11 @@ import (
// Creates a new DestinationRateTiming profile within a tariff plan
func (self *ApierV1) SetTPRatingPlan(attrs utils.TPRatingPlan, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "RatingPlanId", "RatingPlanBindings"}); len(missing) != 0 {
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
rp := engine.APItoModelRatingPlan(&attrs)
if err := self.StorDb.SetTpRatingPlans(rp); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
*reply = "OK"
return nil
@@ -50,12 +47,12 @@ type AttrGetTPRatingPlan struct {
// Queries specific RatingPlan profile on tariff plan
func (self *ApierV1) GetTPRatingPlan(attrs AttrGetTPRatingPlan, reply *utils.TPRatingPlan) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "RatingPlanId"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if rps, err := self.StorDb.GetTpRatingPlans(attrs.TPid, attrs.RatingPlanId, &attrs.Paginator); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if len(rps) == 0 {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
} else {
rpsMap, err := engine.TpRatingPlans(rps).GetRatingPlans()
if err != nil {
@@ -74,12 +71,12 @@ type AttrGetTPRatingPlanIds struct {
// Queries RatingPlan identities on specific tariff plan.
func (self *ApierV1) GetTPRatingPlanIds(attrs AttrGetTPRatingPlanIds, reply *[]string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBL_TP_RATING_PLANS, utils.TPDistinctIds{"tag"}, nil, &attrs.Paginator); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if ids == nil {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
} else {
*reply = ids
}
@@ -89,10 +86,10 @@ func (self *ApierV1) GetTPRatingPlanIds(attrs AttrGetTPRatingPlanIds, reply *[]s
// Removes specific RatingPlan on Tariff plan
func (self *ApierV1) RemTPRatingPlan(attrs AttrGetTPRatingPlan, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "RatingPlanId"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if err := self.StorDb.RemTpData(utils.TBL_TP_RATING_PLANS, attrs.TPid, attrs.RatingPlanId); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else {
*reply = "OK"
}
diff --git a/apier/v1/tpratingprofiles.go b/apier/v1/tpratingprofiles.go
index 136414462..c2cb75dba 100644
--- a/apier/v1/tpratingprofiles.go
+++ b/apier/v1/tpratingprofiles.go
@@ -21,9 +21,6 @@ package v1
// This file deals with tp_rate_profiles management over APIs
import (
- "errors"
- "fmt"
-
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
@@ -31,11 +28,11 @@ import (
// Creates a new RatingProfile within a tariff plan
func (self *ApierV1) SetTPRatingProfile(attrs utils.TPRatingProfile, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "LoadId", "Tenant", "Category", "Direction", "Subject", "RatingPlanActivations"}); len(missing) != 0 {
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
rpf := engine.APItoModelRatingProfile(&attrs)
if err := self.StorDb.SetTpRatingProfiles(rpf); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
*reply = "OK"
return nil
@@ -53,13 +50,13 @@ func (self *ApierV1) GetTPRatingProfilesByLoadId(attrs utils.TPRatingProfile, re
mndtryFlds = append(mndtryFlds, "Tenant", "TOR", "Direction", "Subject")
}
if missing := utils.MissingStructFields(&attrs, mndtryFlds); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
rpf := engine.APItoModelRatingProfile(&attrs)
if dr, err := self.StorDb.GetTpRatingProfiles(&rpf[0]); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if dr == nil {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
} else {
rpfMap, err := engine.TpRatingProfiles(dr).GetRatingProfiles()
if err != nil {
@@ -81,7 +78,7 @@ func (self *ApierV1) GetTPRatingProfilesByLoadId(attrs utils.TPRatingProfile, re
// Queries RatingProfile identities on specific tariff plan.
func (self *ApierV1) GetTPRatingProfileLoadIds(attrs utils.AttrTPRatingProfileIds, reply *[]string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBL_TP_RATE_PROFILES, utils.TPDistinctIds{"loadid"}, map[string]string{
"tenant": attrs.Tenant,
@@ -89,9 +86,9 @@ func (self *ApierV1) GetTPRatingProfileLoadIds(attrs utils.AttrTPRatingProfileId
"direction": attrs.Direction,
"subject": attrs.Subject,
}, new(utils.Paginator)); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if ids == nil {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
} else {
*reply = ids
}
@@ -106,7 +103,7 @@ type AttrGetTPRatingProfile struct {
// Queries specific RatingProfile on tariff plan
func (self *ApierV1) GetTPRatingProfile(attrs AttrGetTPRatingProfile, reply *utils.TPRatingProfile) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "RatingProfileId"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
tmpRpf := &utils.TPRatingProfile{TPid: attrs.TPid}
if err := tmpRpf.SetRatingProfilesId(attrs.RatingProfileId); err != nil {
@@ -114,9 +111,9 @@ func (self *ApierV1) GetTPRatingProfile(attrs AttrGetTPRatingProfile, reply *uti
}
rpf := engine.APItoModelRatingProfile(tmpRpf)
if rpfs, err := self.StorDb.GetTpRatingProfiles(&rpf[0]); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if len(rpfs) == 0 {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
} else {
rpfMap, err := engine.TpRatingProfiles(rpfs).GetRatingProfiles()
if err != nil {
@@ -143,12 +140,12 @@ type AttrGetTPRatingProfileIds struct {
// Queries RatingProfiles identities on specific tariff plan.
func (self *ApierV1) GetTPRatingProfileIds(attrs AttrGetTPRatingProfileIds, reply *[]string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBL_TP_RATE_PROFILES, utils.TPDistinctIds{"loadid", "direction", "tenant", "category", "subject"}, nil, &attrs.Paginator); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if ids == nil {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
} else {
*reply = ids
}
@@ -158,14 +155,14 @@ func (self *ApierV1) GetTPRatingProfileIds(attrs AttrGetTPRatingProfileIds, repl
// Removes specific RatingProfiles on Tariff plan
func (self *ApierV1) RemTPRatingProfile(attrs AttrGetTPRatingProfile, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "RatingProfileId"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
tmpRpf := engine.TpRatingProfile{}
if err := tmpRpf.SetRatingProfileId(attrs.RatingProfileId); err != nil {
return err
}
if err := self.StorDb.RemTpData(utils.TBL_TP_RATE_PROFILES, attrs.TPid, tmpRpf.Loadid, tmpRpf.Direction, tmpRpf.Tenant, tmpRpf.Category, tmpRpf.Subject); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else {
*reply = "OK"
}
diff --git a/apier/v1/tpsharedgroups.go b/apier/v1/tpsharedgroups.go
index ac4823047..83880d614 100644
--- a/apier/v1/tpsharedgroups.go
+++ b/apier/v1/tpsharedgroups.go
@@ -19,9 +19,6 @@ along with this program. If not, see
package v1
import (
- "errors"
- "fmt"
-
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
@@ -29,7 +26,7 @@ import (
// Creates a new SharedGroups profile within a tariff plan
func (self *ApierV1) SetTPSharedGroups(attrs utils.TPSharedGroups, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "SharedGroupsId", "SharedGroups"}); len(missing) != 0 {
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
/*for _, action := range attrs.SharedGroups {
requiredFields := []string{"Identifier", "Weight"}
@@ -42,7 +39,7 @@ func (self *ApierV1) SetTPSharedGroups(attrs utils.TPSharedGroups, reply *string
}*/
sg := engine.APItoModelSharedGroup(&attrs)
if err := self.StorDb.SetTpSharedGroups(sg); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
*reply = "OK"
return nil
@@ -56,12 +53,12 @@ type AttrGetTPSharedGroups struct {
// Queries specific SharedGroup on tariff plan
func (self *ApierV1) GetTPSharedGroups(attrs AttrGetTPSharedGroups, reply *utils.TPSharedGroups) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "SharedGroupsId"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if sgs, err := self.StorDb.GetTpSharedGroups(attrs.TPid, attrs.SharedGroupsId); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if len(sgs) == 0 {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
} else {
sgMap, err := engine.TpSharedGroups(sgs).GetSharedGroups()
if err != nil {
@@ -80,12 +77,12 @@ type AttrGetTPSharedGroupIds struct {
// Queries SharedGroups identities on specific tariff plan.
func (self *ApierV1) GetTPSharedGroupIds(attrs AttrGetTPSharedGroupIds, reply *[]string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBL_TP_SHARED_GROUPS, utils.TPDistinctIds{"tag"}, nil, &attrs.Paginator); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if ids == nil {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
} else {
*reply = ids
}
@@ -95,10 +92,10 @@ func (self *ApierV1) GetTPSharedGroupIds(attrs AttrGetTPSharedGroupIds, reply *[
// Removes specific SharedGroups on Tariff plan
func (self *ApierV1) RemTPSharedGroups(attrs AttrGetTPSharedGroups, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "SharedGroupsId"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if err := self.StorDb.RemTpData(utils.TBL_TP_SHARED_GROUPS, attrs.TPid, attrs.SharedGroupsId); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else {
*reply = "OK"
}
diff --git a/apier/v1/tptimings.go b/apier/v1/tptimings.go
index dc374a806..dcd47421f 100644
--- a/apier/v1/tptimings.go
+++ b/apier/v1/tptimings.go
@@ -19,9 +19,6 @@ along with this program. If not, see
package v1
import (
- "errors"
- "fmt"
-
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
@@ -29,11 +26,11 @@ import (
// Creates a new timing within a tariff plan
func (self *ApierV1) SetTPTiming(attrs utils.ApierTPTiming, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "TimingId", "Years", "Months", "MonthDays", "WeekDays", "Time"}); len(missing) != 0 {
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
tm := engine.APItoModelTiming(&attrs)
if err := self.StorDb.SetTpTimings([]engine.TpTiming{*tm}); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
*reply = "OK"
return nil
@@ -47,12 +44,12 @@ type AttrGetTPTiming struct {
// Queries specific Timing on Tariff plan
func (self *ApierV1) GetTPTiming(attrs AttrGetTPTiming, reply *utils.ApierTPTiming) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "TimingId"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if tms, err := self.StorDb.GetTpTimings(attrs.TPid, attrs.TimingId); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if len(tms) == 0 {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
} else {
tmMap, err := engine.TpTimings(tms).GetApierTimings()
if err != nil {
@@ -71,12 +68,12 @@ type AttrGetTPTimingIds struct {
// Queries timing identities on specific tariff plan.
func (self *ApierV1) GetTPTimingIds(attrs AttrGetTPTimingIds, reply *[]string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBL_TP_TIMINGS, utils.TPDistinctIds{"tag"}, nil, &attrs.Paginator); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if ids == nil {
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
} else {
*reply = ids
}
@@ -86,10 +83,10 @@ func (self *ApierV1) GetTPTimingIds(attrs AttrGetTPTimingIds, reply *[]string) e
// Removes specific Timing on Tariff plan
func (self *ApierV1) RemTPTiming(attrs AttrGetTPTiming, reply *string) error {
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "TimingId"}); len(missing) != 0 { //Params missing
- return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
+ return utils.NewErrMandatoryIeMissing(missing...)
}
if err := self.StorDb.RemTpData(utils.TBL_TP_TIMINGS, attrs.TPid, attrs.TimingId); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else {
*reply = "OK"
}
diff --git a/apier/v2/apier.go b/apier/v2/apier.go
index a23400a0c..d65c9d7a8 100644
--- a/apier/v2/apier.go
+++ b/apier/v2/apier.go
@@ -19,8 +19,6 @@ along with this program. If not, see
package v2
import (
- "fmt"
-
"github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
@@ -38,14 +36,14 @@ type AttrLoadRatingProfile struct {
// Process dependencies and load a specific rating profile from storDb into dataDb.
func (self *ApierV2) LoadRatingProfile(attrs AttrLoadRatingProfile, reply *string) error {
if len(attrs.TPid) == 0 {
- return fmt.Errorf("%s:%s", utils.ERR_MANDATORY_IE_MISSING, "TPid")
+ return utils.NewErrMandatoryIeMissing("TPid")
}
tpRpf := &utils.TPRatingProfile{TPid: attrs.TPid}
tpRpf.SetRatingProfilesId(attrs.RatingProfileId)
rpf := engine.APItoModelRatingProfile(tpRpf)
dbReader := engine.NewTpReader(self.RatingDb, self.AccountDb, self.StorDb, attrs.TPid)
if err := dbReader.LoadRatingProfilesFiltered(&rpf[0]); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
//Automatic cache of the newly inserted rating profile
didNotChange := []string{}
@@ -68,7 +66,7 @@ type AttrLoadAccountActions struct {
// Process dependencies and load a specific AccountActions profile from storDb into dataDb.
func (self *ApierV2) LoadAccountActions(attrs AttrLoadAccountActions, reply *string) error {
if len(attrs.TPid) == 0 {
- return fmt.Errorf("%s:%s", utils.ERR_MANDATORY_IE_MISSING, "TPid")
+ return utils.NewErrMandatoryIeMissing("TPid")
}
dbReader := engine.NewTpReader(self.RatingDb, self.AccountDb, self.StorDb, attrs.TPid)
tpAa := &utils.TPAccountActions{TPid: attrs.TPid}
@@ -80,7 +78,7 @@ func (self *ApierV2) LoadAccountActions(attrs AttrLoadAccountActions, reply *str
}
return 0, nil
}, attrs.AccountActionsId); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
// ToDo: Get the action keys loaded by dbReader so we reload only these in cache
// Need to do it before scheduler otherwise actions to run will be unknown
@@ -103,14 +101,14 @@ type AttrLoadDerivedChargers struct {
// Load derived chargers from storDb into dataDb.
func (self *ApierV2) LoadDerivedChargers(attrs AttrLoadDerivedChargers, reply *string) error {
if len(attrs.TPid) == 0 {
- return fmt.Errorf("%s:%s", utils.ERR_MANDATORY_IE_MISSING, "TPid")
+ return utils.NewErrMandatoryIeMissing("TPid")
}
tpDc := &utils.TPDerivedChargers{TPid: attrs.TPid}
tpDc.SetDerivedChargersId(attrs.DerivedChargersId)
dc := engine.APItoModelDerivedCharger(tpDc)
dbReader := engine.NewTpReader(self.RatingDb, self.AccountDb, self.StorDb, attrs.TPid)
if err := dbReader.LoadDerivedChargersFiltered(&dc[0], true); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
//Automatic cache of the newly inserted rating plan
didNotChange := []string{}
diff --git a/apier/v2/cdre.go b/apier/v2/cdre.go
index cc0160fc1..9db571018 100644
--- a/apier/v2/cdre.go
+++ b/apier/v2/cdre.go
@@ -37,7 +37,7 @@ func (self *ApierV2) ExportCdrsToFile(attr utils.AttrExportCdrsToFile, reply *ut
if attr.ExportTemplate != nil && len(*attr.ExportTemplate) != 0 { // Export template prefered, use it
var hasIt bool
if exportTemplate, hasIt = self.Config.CdreProfiles[*attr.ExportTemplate]; !hasIt {
- return fmt.Errorf("%s:ExportTemplate", utils.ERR_NOT_FOUND)
+ return fmt.Errorf("%s:ExportTemplate", utils.ErrNotFound)
}
}
cdrFormat := exportTemplate.CdrFormat
@@ -45,13 +45,13 @@ func (self *ApierV2) ExportCdrsToFile(attr utils.AttrExportCdrsToFile, reply *ut
cdrFormat = strings.ToLower(*attr.CdrFormat)
}
if !utils.IsSliceMember(utils.CdreCdrFormats, cdrFormat) {
- return fmt.Errorf("%s:%s", utils.ERR_MANDATORY_IE_MISSING, "CdrFormat")
+ return utils.NewErrMandatoryIeMissing("CdrFormat")
}
fieldSep := exportTemplate.FieldSeparator
if attr.FieldSeparator != nil && len(*attr.FieldSeparator) != 0 {
fieldSep, _ = utf8.DecodeRuneInString(*attr.FieldSeparator)
if fieldSep == utf8.RuneError {
- return fmt.Errorf("%s:FieldSeparator:%s", utils.ERR_SERVER_ERROR, "Invalid")
+ return fmt.Errorf("%s:FieldSeparator:%s", utils.ErrServerError, "Invalid")
}
}
exportDir := exportTemplate.ExportDir
@@ -104,7 +104,7 @@ func (self *ApierV2) ExportCdrsToFile(attr utils.AttrExportCdrsToFile, reply *ut
}
cdrsFltr, err := attr.RpcCdrsFilter.AsCdrsFilter()
if err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
cdrs, _, err := self.CdrDb.GetStoredCdrs(cdrsFltr)
if err != nil {
@@ -116,14 +116,14 @@ func (self *ApierV2) ExportCdrsToFile(attr utils.AttrExportCdrsToFile, reply *ut
cdrexp, err := cdre.NewCdrExporter(cdrs, self.CdrDb, exportTemplate, cdrFormat, fieldSep, exportId, dataUsageMultiplyFactor, smsUsageMultiplyFactor, genericUsageMultiplyFactor,
costMultiplyFactor, costShiftDigits, roundingDecimals, self.Config.RoundingDecimals, maskDestId, maskLen, self.Config.HttpSkipTlsVerify)
if err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
if cdrexp.TotalExportedCdrs() == 0 {
*reply = utils.ExportedFileCdrs{ExportedFilePath: ""}
return nil
}
if err := cdrexp.WriteToFile(filePath); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
*reply = utils.ExportedFileCdrs{ExportedFilePath: filePath, TotalRecords: len(cdrs), TotalCost: cdrexp.TotalCost(), FirstOrderId: cdrexp.FirstOrderId(), LastOrderId: cdrexp.LastOrderId()}
if !attr.SuppressCgrIds {
diff --git a/apier/v2/cdrs.go b/apier/v2/cdrs.go
index 262f9cfce..1ca28036a 100644
--- a/apier/v2/cdrs.go
+++ b/apier/v2/cdrs.go
@@ -19,7 +19,6 @@ along with this program. If not, see
package v2
import (
- "fmt"
"github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/engine"
@@ -30,10 +29,10 @@ import (
func (apier *ApierV2) GetCdrs(attrs utils.RpcCdrsFilter, reply *[]*engine.ExternalCdr) error {
cdrsFltr, err := attrs.AsCdrsFilter()
if err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
if cdrs, _, err := apier.CdrDb.GetStoredCdrs(cdrsFltr); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else if len(cdrs) == 0 {
*reply = make([]*engine.ExternalCdr, 0)
} else {
@@ -47,11 +46,11 @@ func (apier *ApierV2) GetCdrs(attrs utils.RpcCdrsFilter, reply *[]*engine.Extern
func (apier *ApierV2) CountCdrs(attrs utils.RpcCdrsFilter, reply *int64) error {
cdrsFltr, err := attrs.AsCdrsFilter()
if err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
cdrsFltr.Count = true
if _, count, err := apier.CdrDb.GetStoredCdrs(cdrsFltr); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else {
*reply = count
}
diff --git a/apier/v2/tp.go b/apier/v2/tp.go
index f23072291..492eb85d5 100644
--- a/apier/v2/tp.go
+++ b/apier/v2/tp.go
@@ -20,7 +20,6 @@ package v2
import (
"encoding/base64"
- "fmt"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
@@ -32,10 +31,10 @@ type AttrRemTp struct {
func (self *ApierV2) RemTP(attrs AttrRemTp, reply *string) error {
if len(attrs.TPid) == 0 {
- return fmt.Errorf("%s:TPid", utils.ERR_MANDATORY_IE_MISSING)
+ return utils.NewErrMandatoryIeMissing("TPid")
}
if err := self.StorDb.RemTpData("", attrs.TPid); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else {
*reply = "OK"
}
@@ -44,7 +43,7 @@ func (self *ApierV2) RemTP(attrs AttrRemTp, reply *string) error {
func (self *ApierV2) ExportTPToFolder(attrs utils.AttrDirExportTP, exported *utils.ExportedTPStats) error {
if len(*attrs.TPid) == 0 {
- return fmt.Errorf("%s:TPid", utils.ERR_MANDATORY_IE_MISSING)
+ return utils.NewErrMandatoryIeMissing("TPid")
}
dir := self.Config.TpExportPath
if attrs.ExportPath != nil {
@@ -64,10 +63,10 @@ func (self *ApierV2) ExportTPToFolder(attrs utils.AttrDirExportTP, exported *uti
}
tpExporter, err := engine.NewTPExporter(self.StorDb, *attrs.TPid, dir, fileFormat, sep, compress)
if err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
if err := tpExporter.Run(); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
} else {
*exported = *tpExporter.ExportStats()
}
@@ -77,7 +76,7 @@ func (self *ApierV2) ExportTPToFolder(attrs utils.AttrDirExportTP, exported *uti
func (self *ApierV2) ExportTPToZipString(attrs utils.AttrDirExportTP, reply *string) error {
if len(*attrs.TPid) == 0 {
- return fmt.Errorf("%s:TPid", utils.ERR_MANDATORY_IE_MISSING)
+ return utils.NewErrMandatoryIeMissing("TPid")
}
dir := ""
fileFormat := utils.CSV
@@ -90,10 +89,10 @@ func (self *ApierV2) ExportTPToZipString(attrs utils.AttrDirExportTP, reply *str
}
tpExporter, err := engine.NewTPExporter(self.StorDb, *attrs.TPid, dir, fileFormat, sep, true)
if err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
if err := tpExporter.Run(); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
*reply = base64.StdEncoding.EncodeToString(tpExporter.GetCacheBuffer().Bytes())
return nil
diff --git a/cache2go/store.go b/cache2go/store.go
index 3550164c7..fe0e74d78 100644
--- a/cache2go/store.go
+++ b/cache2go/store.go
@@ -2,7 +2,6 @@
package cache2go
import (
- "errors"
"strings"
"time"
@@ -54,7 +53,7 @@ func (cs cacheDoubleStore) Get(key string) (interface{}, error) {
return ti.value, nil
}
}
- return nil, errors.New(utils.ERR_NOT_FOUND)
+ return nil, utils.ErrNotFound
}
func (cs cacheDoubleStore) GetAge(key string) (time.Duration, error) {
@@ -64,7 +63,7 @@ func (cs cacheDoubleStore) GetAge(key string) (time.Duration, error) {
return time.Since(ti.timestamp), nil
}
}
- return -1, errors.New(utils.ERR_NOT_FOUND)
+ return -1, utils.ErrNotFound
}
func (cs cacheDoubleStore) Delete(key string) {
@@ -89,7 +88,7 @@ func (cs cacheDoubleStore) GetAllForPrefix(prefix string) (map[string]timestampe
if keyMap, ok := cs[prefix]; ok {
return keyMap, nil
}
- return nil, errors.New(utils.ERR_NOT_FOUND)
+ return nil, utils.ErrNotFound
}
func (cs cacheDoubleStore) GetKeysForPrefix(prefix string) (keys []string) {
@@ -140,7 +139,7 @@ func (cs cacheSimpleStore) Get(key string) (interface{}, error) {
if ti, exists := cs.cache[key]; exists {
return ti.value, nil
}
- return nil, errors.New(utils.ERR_NOT_FOUND)
+ return nil, utils.ErrNotFound
}
func (cs cacheSimpleStore) GetAge(key string) (time.Duration, error) {
@@ -148,7 +147,7 @@ func (cs cacheSimpleStore) GetAge(key string) (time.Duration, error) {
return time.Since(ti.timestamp), nil
}
- return -1, errors.New(utils.ERR_NOT_FOUND)
+ return -1, utils.ErrNotFound
}
func (cs cacheSimpleStore) Delete(key string) {
@@ -209,7 +208,7 @@ func (cs cacheSimpleStore) GetAllForPrefix(prefix string) (map[string]timestampe
}
}
if !found {
- return nil, errors.New(utils.ERR_NOT_FOUND)
+ return nil, utils.ErrNotFound
}
return result, nil
}
diff --git a/cdre/cdrexporter.go b/cdre/cdrexporter.go
index 0194f21eb..ababd993c 100644
--- a/cdre/cdrexporter.go
+++ b/cdre/cdrexporter.go
@@ -487,12 +487,12 @@ func (cdre *CdrExporter) WriteToFile(filePath string) error {
return nil
case utils.CDRE_FIXED_WIDTH:
if err := cdre.writeOut(fileOut); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
case utils.CSV:
csvWriter := csv.NewWriter(fileOut)
if err := cdre.writeCsv(csvWriter); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
}
return nil
diff --git a/data/docker/devel/start.sh b/data/docker/devel/start.sh
index 975d5831b..5f7b137f0 100755
--- a/data/docker/devel/start.sh
+++ b/data/docker/devel/start.sh
@@ -31,6 +31,5 @@ cd /root/cgr
echo "for cgradmin run: cgr-engine -config_dir data/conf/samples/cgradmin"
echo 'export GOROOT=/root/go; export GOPATH=/root/code; export PATH=$GOROOT/bin:$GOPATH/bin:$PATH'>>/root/.zshrc
-upgrade_oh_my_zsh
-
+/bin/sh /root/.oh-my-zsh/tools/upgrade.sh
zsh
diff --git a/engine/actions_local_test.go b/engine/actions_local_test.go
index 0b0e7a3ef..97b762509 100644
--- a/engine/actions_local_test.go
+++ b/engine/actions_local_test.go
@@ -92,7 +92,7 @@ func TestActionsLocalSetCdrlogActions(t *testing.T) {
&utils.TPAction{Identifier: DEBIT, BalanceType: utils.MONETARY, Direction: attrsSetAccount.Direction, Units: 5.0, ExpiryTime: UNLIMITED, Weight: 20.0},
&utils.TPAction{Identifier: CDRLOG},
}}
- if err := actsLclRpc.Call("ApierV1.SetActions", attrsAA, &reply); err != nil && err.Error() != utils.ERR_EXISTS {
+ if err := actsLclRpc.Call("ApierV1.SetActions", attrsAA, &reply); err != nil && err != utils.ErrExists {
t.Error("Got error on ApierV1.SetActions: ", err.Error())
} else if reply != utils.OK {
t.Errorf("Calling ApierV1.SetActions received: %s", reply)
diff --git a/engine/calldesc.go b/engine/calldesc.go
index d93681b9f..fa490aee9 100644
--- a/engine/calldesc.go
+++ b/engine/calldesc.go
@@ -719,13 +719,13 @@ func (cd *CallDescriptor) GetLCRFromStorage() (*LCR, error) {
utils.LCRKey(utils.ANY, utils.ANY, utils.ANY, utils.ANY, utils.ANY),
}
for _, key := range keyVariants {
- if lcr, err := ratingStorage.GetLCR(key, false); err != nil && err.Error() != utils.ERR_NOT_FOUND {
+ if lcr, err := ratingStorage.GetLCR(key, false); err != nil && err != utils.ErrNotFound {
return nil, err
} else if err == nil {
return lcr, nil
}
}
- return nil, errors.New(utils.ERR_NOT_FOUND)
+ return nil, utils.ErrNotFound
}
func (cd *CallDescriptor) GetLCR(stats StatsInterface) (*LCRCost, error) {
diff --git a/engine/cdrs.go b/engine/cdrs.go
index e8c3018f6..b634dd0fa 100644
--- a/engine/cdrs.go
+++ b/engine/cdrs.go
@@ -19,7 +19,6 @@ along with this program. If not, see
package engine
import (
- "errors"
"fmt"
"io/ioutil"
"net/http"
@@ -115,7 +114,7 @@ func (self *CdrServer) LogCallCost(ccl *CallCostLog) error {
return err
}
if cc != nil {
- return errors.New(utils.ERR_EXISTS)
+ return utils.ErrExists
}
}
return self.cdrDb.LogCallCost(ccl.CgrId, ccl.Source, ccl.RunId, ccl.CallCost)
diff --git a/engine/handler_derivedcharging.go b/engine/handler_derivedcharging.go
index 5f0c2b125..ecf0a0d69 100644
--- a/engine/handler_derivedcharging.go
+++ b/engine/handler_derivedcharging.go
@@ -31,7 +31,7 @@ func HandleGetDerivedChargers(ratingStorage RatingStorage, attrs *utils.AttrDeri
anyCategKey := utils.DerivedChargersKey(attrs.Direction, attrs.Tenant, utils.ANY, utils.ANY, utils.ANY)
anyTenantKey := utils.DerivedChargersKey(attrs.Direction, utils.ANY, utils.ANY, utils.ANY, utils.ANY)
for _, dcKey := range []string{strictKey, anySubjKey, anyAcntKey, anyCategKey, anyTenantKey} {
- if dcsDb, err := ratingStorage.GetDerivedChargers(dcKey, false); err != nil && err.Error() != utils.ERR_NOT_FOUND {
+ if dcsDb, err := ratingStorage.GetDerivedChargers(dcKey, false); err != nil && err != utils.ErrNotFound {
return nil, err
} else if dcsDb != nil {
dcs = dcsDb
diff --git a/engine/lcr.go b/engine/lcr.go
index c38fb82b5..6d86c1702 100644
--- a/engine/lcr.go
+++ b/engine/lcr.go
@@ -19,7 +19,6 @@ along with this program. If not, see
package engine
import (
- "errors"
"fmt"
"sort"
"strconv"
@@ -53,7 +52,7 @@ type LcrRequest struct {
func (self *LcrRequest) AsCallDescriptor() (*CallDescriptor, error) {
if len(self.Account) == 0 || len(self.Destination) == 0 {
- return nil, errors.New(utils.ERR_MANDATORY_IE_MISSING)
+ return nil, utils.ErrMandatoryIeMissing
}
// Set defaults
if len(self.Direction) == 0 {
@@ -310,7 +309,7 @@ func (lc *LCRCost) LogErrors() {
func (lc *LCRCost) SuppliersString() (string, error) {
supplStr := ""
if lc.Entry == nil {
- return "", errors.New(utils.ERR_NOT_FOUND)
+ return "", utils.ErrNotFound
}
for idx, supplCost := range lc.SupplierCosts {
if dtcs, err := utils.NewDTCSFromRPKey(supplCost.Supplier); err != nil {
diff --git a/engine/lcr_test.go b/engine/lcr_test.go
index 73b0f4ef9..bb7f00783 100644
--- a/engine/lcr_test.go
+++ b/engine/lcr_test.go
@@ -213,7 +213,7 @@ func TestLcrRequestAsCallDescriptor(t *testing.T) {
sTime := time.Date(2015, 04, 06, 17, 40, 0, 0, time.UTC)
callDur := time.Duration(1) * time.Minute
lcrReq := &LcrRequest{Account: "1001", StartTime: sTime.String()}
- if _, err := lcrReq.AsCallDescriptor(); err == nil || err.Error() != utils.ERR_MANDATORY_IE_MISSING {
+ if _, err := lcrReq.AsCallDescriptor(); err == nil || err != utils.ErrMandatoryIeMissing {
t.Error("Unexpected error received: %v", err)
}
lcrReq = &LcrRequest{Account: "1001", Destination: "1002", StartTime: sTime.String()}
@@ -236,7 +236,7 @@ func TestLcrRequestAsCallDescriptor(t *testing.T) {
func TestLCRCostSuppliersString(t *testing.T) {
lcrCost := new(LCRCost)
- if _, err := lcrCost.SuppliersString(); err == nil || err.Error() != utils.ERR_NOT_FOUND {
+ if _, err := lcrCost.SuppliersString(); err == nil || err != utils.ErrNotFound {
t.Errorf("Unexpected error received: %v", err)
}
lcrCost = &LCRCost{
diff --git a/engine/libtest.go b/engine/libtest.go
index 029a72aba..04efb0ce6 100644
--- a/engine/libtest.go
+++ b/engine/libtest.go
@@ -108,10 +108,10 @@ func LoadTariffPlanFromFolder(tpPath string, ratingDb RatingStorage, accountingD
path.Join(tpPath, utils.DERIVED_CHARGERS_CSV),
path.Join(tpPath, utils.CDR_STATS_CSV)), "")
if err := loader.LoadAll(); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
if err := loader.WriteToDatabase(false, false); err != nil {
- return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
+ return utils.NewErrServerError(err)
}
return nil
}
diff --git a/engine/ratingprofile.go b/engine/ratingprofile.go
index 3e00bf61e..b1bb04bf6 100644
--- a/engine/ratingprofile.go
+++ b/engine/ratingprofile.go
@@ -20,7 +20,6 @@ package engine
import (
"encoding/json"
- "errors"
"fmt"
"sort"
"time"
@@ -196,7 +195,7 @@ func (rp *RatingProfile) GetRatingPlansForPrefix(cd *CallDescriptor) (err error)
return
}
- return errors.New(utils.ERR_NOT_FOUND)
+ return utils.ErrNotFound
}
// history record method
diff --git a/engine/storage_csv.go b/engine/storage_csv.go
index f804b19c9..371fbf9b7 100644
--- a/engine/storage_csv.go
+++ b/engine/storage_csv.go
@@ -2,7 +2,6 @@ package engine
import (
"encoding/csv"
- "errors"
"io"
"log"
"os"
@@ -460,9 +459,9 @@ func (csvs *CSVStorage) GetTpCdrStats(tpid, tag string) ([]TpCdrstat, error) {
}
func (csvs *CSVStorage) GetTpIds() ([]string, error) {
- return nil, errors.New(utils.ERR_NOT_IMPLEMENTED)
+ return nil, utils.ErrNotImplemented
}
func (csvs *CSVStorage) GetTpTableIds(tpid, table string, distinct utils.TPDistinctIds, filters map[string]string, p *utils.Paginator) ([]string, error) {
- return nil, errors.New(utils.ERR_NOT_IMPLEMENTED)
+ return nil, utils.ErrNotImplemented
}
diff --git a/engine/storage_map.go b/engine/storage_map.go
index 27598638a..99a0ae110 100644
--- a/engine/storage_map.go
+++ b/engine/storage_map.go
@@ -206,7 +206,7 @@ func (ms *MapStorage) GetRatingPlan(key string, skipCache bool) (rp *RatingPlan,
err = ms.ms.Unmarshal(out, rp)
cache2go.Cache(key, rp)
} else {
- return nil, errors.New(utils.ERR_NOT_FOUND)
+ return nil, utils.ErrNotFound
}
return
}
@@ -241,7 +241,7 @@ func (ms *MapStorage) GetRatingProfile(key string, skipCache bool) (rpf *RatingP
err = ms.ms.Unmarshal(values, rpf)
cache2go.Cache(key, rpf)
} else {
- return nil, errors.New(utils.ERR_NOT_FOUND)
+ return nil, utils.ErrNotFound
}
return
}
@@ -270,7 +270,7 @@ func (ms *MapStorage) GetLCR(key string, skipCache bool) (lcr *LCR, err error) {
err = ms.ms.Unmarshal(values, &lcr)
cache2go.Cache(key, lcr)
} else {
- return nil, errors.New(utils.ERR_NOT_FOUND)
+ return nil, utils.ErrNotFound
}
return
}
@@ -295,7 +295,7 @@ func (ms *MapStorage) GetRpAlias(key string, skipCache bool) (alias string, err
alias = string(values)
cache2go.Cache(key, alias)
} else {
- return "", errors.New(utils.ERR_NOT_FOUND)
+ return "", utils.ErrNotFound
}
return
}
@@ -362,7 +362,7 @@ func (ms *MapStorage) GetAccAlias(key string, skipCache bool) (alias string, err
alias = string(values)
cache2go.Cache(key, alias)
} else {
- return "", errors.New(utils.ERR_NOT_FOUND)
+ return "", utils.ErrNotFound
}
return
}
@@ -415,7 +415,7 @@ func (ms *MapStorage) GetDestination(key string) (dest *Destination, err error)
cache2go.CachePush(DESTINATION_PREFIX+p, dest.Id)
}
} else {
- return nil, errors.New(utils.ERR_NOT_FOUND)
+ return nil, utils.ErrNotFound
}
return
}
@@ -448,7 +448,7 @@ func (ms *MapStorage) GetActions(key string, skipCache bool) (as Actions, err er
err = ms.ms.Unmarshal(values, &as)
cache2go.Cache(key, as)
} else {
- return nil, errors.New(utils.ERR_NOT_FOUND)
+ return nil, utils.ErrNotFound
}
return
}
@@ -473,7 +473,7 @@ func (ms *MapStorage) GetSharedGroup(key string, skipCache bool) (sg *SharedGrou
err = ms.ms.Unmarshal(values, &sg)
cache2go.Cache(key, sg)
} else {
- return nil, errors.New(utils.ERR_NOT_FOUND)
+ return nil, utils.ErrNotFound
}
return
}
@@ -490,7 +490,7 @@ func (ms *MapStorage) GetAccount(key string) (ub *Account, err error) {
ub = &Account{Id: key}
err = ms.ms.Unmarshal(values, ub)
} else {
- return nil, errors.New(utils.ERR_NOT_FOUND)
+ return nil, utils.ErrNotFound
}
return
}
@@ -517,7 +517,7 @@ func (ms *MapStorage) GetActionPlans(key string) (ats ActionPlans, err error) {
if values, ok := ms.dict[ACTION_TIMING_PREFIX+key]; ok {
err = ms.ms.Unmarshal(values, &ats)
} else {
- return nil, errors.New(utils.ERR_NOT_FOUND)
+ return nil, utils.ErrNotFound
}
return
}
@@ -560,7 +560,7 @@ func (ms *MapStorage) GetDerivedChargers(key string, skipCache bool) (dcs utils.
err = ms.ms.Unmarshal(values, &dcs)
cache2go.Cache(key, dcs)
} else {
- return nil, errors.New(utils.ERR_NOT_FOUND)
+ return nil, utils.ErrNotFound
}
return
}
@@ -581,7 +581,7 @@ func (ms *MapStorage) GetCdrStats(key string) (cs *CdrStats, err error) {
if values, ok := ms.dict[CDR_STATS_PREFIX+key]; ok {
err = ms.ms.Unmarshal(values, &cs)
} else {
- return nil, errors.New(utils.ERR_NOT_FOUND)
+ return nil, utils.ErrNotFound
}
return
}
@@ -608,7 +608,7 @@ func (ms *MapStorage) GetCallCostLog(cgrid, source, runid string) (cc *CallCost,
if values, ok := ms.dict[LOG_CALL_COST_PREFIX+source+runid+"_"+cgrid]; ok {
err = ms.ms.Unmarshal(values, &cc)
} else {
- return nil, errors.New(utils.ERR_NOT_FOUND)
+ return nil, utils.ErrNotFound
}
return
}
diff --git a/engine/storage_sql.go b/engine/storage_sql.go
index e5393e931..42f17e705 100644
--- a/engine/storage_sql.go
+++ b/engine/storage_sql.go
@@ -22,7 +22,6 @@ import (
"bytes"
"database/sql"
"encoding/json"
- "errors"
"fmt"
"io/ioutil"
"strconv"
@@ -46,7 +45,7 @@ func (self *SQLStorage) Close() {
}
func (self *SQLStorage) Flush(placeholder string) (err error) {
- return errors.New(utils.ERR_NOT_IMPLEMENTED)
+ return utils.ErrNotImplemented
}
func (self *SQLStorage) GetKeysForPrefix(prefix string) ([]string, error) {
@@ -562,7 +561,7 @@ func (self *SQLStorage) SetTpAccountActions(aas []TpAccountAction) error {
}
func (self *SQLStorage) LogCallCost(cgrid, source, runid string, cc *CallCost) error {
- return errors.New(utils.ERR_NOT_IMPLEMENTED)
+ return utils.ErrNotImplemented
}
func (self *SQLStorage) GetCallCostLog(cgrid, source, runid string) (*CallCost, error) {
@@ -636,7 +635,7 @@ func (self *SQLStorage) SetCdr(cdr *StoredCdr) error {
}
func (self *SQLStorage) SetRatedCdr(storedCdr *StoredCdr) error {
- return errors.New(utils.ERR_NOT_IMPLEMENTED)
+ return utils.ErrNotImplemented
}
func (self *SQLStorage) GetStoredCdrs(qryFltr *utils.CdrsFilter) ([]*StoredCdr, int64, error) {
diff --git a/engine/storedcdr.go b/engine/storedcdr.go
index fdc87bb46..4658199b7 100644
--- a/engine/storedcdr.go
+++ b/engine/storedcdr.go
@@ -20,8 +20,6 @@ package engine
import (
"encoding/json"
- "errors"
- "fmt"
"math"
"net/url"
"strconv"
@@ -328,53 +326,53 @@ func (storedCdr *StoredCdr) ForkCdr(runId string, reqTypeFld, directionFld, tena
frkStorCdr.CdrSource = storedCdr.CdrSource
frkStorCdr.ReqType = storedCdr.FieldAsString(reqTypeFld)
if primaryMandatory && len(frkStorCdr.ReqType) == 0 {
- return nil, errors.New(fmt.Sprintf("%s:%s:%s", utils.ERR_MANDATORY_IE_MISSING, utils.REQTYPE, reqTypeFld.Id))
+ return nil, utils.NewErrMandatoryIeMissing(utils.REQTYPE, reqTypeFld.Id)
}
frkStorCdr.Direction = storedCdr.FieldAsString(directionFld)
if primaryMandatory && len(frkStorCdr.Direction) == 0 {
- return nil, errors.New(fmt.Sprintf("%s:%s:%s", utils.ERR_MANDATORY_IE_MISSING, utils.DIRECTION, directionFld.Id))
+ return nil, utils.NewErrMandatoryIeMissing(utils.DIRECTION, directionFld.Id)
}
frkStorCdr.Tenant = storedCdr.FieldAsString(tenantFld)
if primaryMandatory && len(frkStorCdr.Tenant) == 0 {
- return nil, errors.New(fmt.Sprintf("%s:%s:%s", utils.ERR_MANDATORY_IE_MISSING, utils.TENANT, tenantFld.Id))
+ return nil, utils.NewErrMandatoryIeMissing(utils.TENANT, tenantFld.Id)
}
frkStorCdr.Category = storedCdr.FieldAsString(categFld)
if primaryMandatory && len(frkStorCdr.Category) == 0 {
- return nil, errors.New(fmt.Sprintf("%s:%s:%s", utils.ERR_MANDATORY_IE_MISSING, utils.CATEGORY, categFld.Id))
+ return nil, utils.NewErrMandatoryIeMissing(utils.CATEGORY, categFld.Id)
}
frkStorCdr.Account = storedCdr.FieldAsString(accountFld)
if primaryMandatory && len(frkStorCdr.Account) == 0 {
- return nil, errors.New(fmt.Sprintf("%s:%s:%s", utils.ERR_MANDATORY_IE_MISSING, utils.ACCOUNT, accountFld.Id))
+ return nil, utils.NewErrMandatoryIeMissing(utils.ACCOUNT, accountFld.Id)
}
frkStorCdr.Subject = storedCdr.FieldAsString(subjectFld)
if primaryMandatory && len(frkStorCdr.Subject) == 0 {
- return nil, errors.New(fmt.Sprintf("%s:%s:%s", utils.ERR_MANDATORY_IE_MISSING, utils.SUBJECT, subjectFld.Id))
+ return nil, utils.NewErrMandatoryIeMissing(utils.SUBJECT, subjectFld.Id)
}
frkStorCdr.Destination = storedCdr.FieldAsString(destFld)
if primaryMandatory && len(frkStorCdr.Destination) == 0 && frkStorCdr.TOR == utils.VOICE {
- return nil, errors.New(fmt.Sprintf("%s:%s:%s", utils.ERR_MANDATORY_IE_MISSING, utils.DESTINATION, destFld.Id))
+ return nil, utils.NewErrMandatoryIeMissing(utils.DESTINATION, destFld.Id)
}
sTimeStr := storedCdr.FieldAsString(setupTimeFld)
if primaryMandatory && len(sTimeStr) == 0 {
- return nil, errors.New(fmt.Sprintf("%s:%s:%s", utils.ERR_MANDATORY_IE_MISSING, utils.SETUP_TIME, setupTimeFld.Id))
+ return nil, utils.NewErrMandatoryIeMissing(utils.SETUP_TIME, setupTimeFld.Id)
} else if frkStorCdr.SetupTime, err = utils.ParseTimeDetectLayout(sTimeStr); err != nil {
return nil, err
}
aTimeStr := storedCdr.FieldAsString(answerTimeFld)
if primaryMandatory && len(aTimeStr) == 0 {
- return nil, errors.New(fmt.Sprintf("%s:%s:%s", utils.ERR_MANDATORY_IE_MISSING, utils.ANSWER_TIME, answerTimeFld.Id))
+ return nil, utils.NewErrMandatoryIeMissing(utils.ANSWER_TIME, answerTimeFld.Id)
} else if frkStorCdr.AnswerTime, err = utils.ParseTimeDetectLayout(aTimeStr); err != nil {
return nil, err
}
durStr := storedCdr.FieldAsString(durationFld)
if primaryMandatory && len(durStr) == 0 {
- return nil, errors.New(fmt.Sprintf("%s:%s:%s", utils.ERR_MANDATORY_IE_MISSING, utils.USAGE, durationFld.Id))
+ return nil, utils.NewErrMandatoryIeMissing(utils.USAGE, durationFld.Id)
} else if frkStorCdr.Usage, err = utils.ParseDurationWithSecs(durStr); err != nil {
return nil, err
}
pddStr := storedCdr.FieldAsString(pddFld)
if primaryMandatory && len(pddStr) == 0 {
- return nil, errors.New(fmt.Sprintf("%s:%s:%s", utils.ERR_MANDATORY_IE_MISSING, utils.PDD, pddFld.Id))
+ return nil, utils.NewErrMandatoryIeMissing(utils.PDD, pddFld.Id)
} else if frkStorCdr.Pdd, err = utils.ParseDurationWithSecs(pddStr); err != nil {
return nil, err
}
diff --git a/sessionmanager/kamailiosm.go b/sessionmanager/kamailiosm.go
index 920eb6835..9bb42a4e0 100644
--- a/sessionmanager/kamailiosm.go
+++ b/sessionmanager/kamailiosm.go
@@ -54,7 +54,7 @@ func (self *KamailioSessionManager) onCgrAuth(evData []byte, connId string) {
return
}
if kev.MissingParameter() {
- if kar, err := kev.AsKamAuthReply(0.0, "", errors.New(utils.ERR_MANDATORY_IE_MISSING)); err != nil {
+ if kar, err := kev.AsKamAuthReply(0.0, "", utils.ErrMandatoryIeMissing); err != nil {
engine.Logger.Err(fmt.Sprintf(" Failed building auth reply %s", err.Error()))
} else if err = self.conns[connId].Send(kar.String()); err != nil {
engine.Logger.Err(fmt.Sprintf(" Failed sending auth reply %s", err.Error()))
@@ -127,7 +127,7 @@ func (self *KamailioSessionManager) onCallStart(evData []byte, connId string) {
return
}
if kamEv.MissingParameter() {
- self.DisconnectSession(kamEv, connId, utils.ERR_MANDATORY_IE_MISSING)
+ self.DisconnectSession(kamEv, connId, utils.ErrMandatoryIeMissing.Error())
return
}
s := NewSession(kamEv, connId, self)
diff --git a/sessionmanager/kamevent.go b/sessionmanager/kamevent.go
index c67362abe..b5f0d479b 100644
--- a/sessionmanager/kamevent.go
+++ b/sessionmanager/kamevent.go
@@ -20,7 +20,6 @@ package sessionmanager
import (
"encoding/json"
- "fmt"
"strconv"
"strings"
"time"
@@ -359,13 +358,13 @@ func (kev KamEvent) AsKamAuthReply(maxSessionTime float64, suppliers string, res
kar.Error = resErr.Error()
}
if _, hasIt := kev[KAM_TR_INDEX]; !hasIt {
- return nil, fmt.Errorf("%s:%s", utils.ERR_MANDATORY_IE_MISSING, KAM_TR_INDEX)
+ return nil, utils.NewErrMandatoryIeMissing(KAM_TR_INDEX, "")
}
if kar.TransactionIndex, err = strconv.Atoi(kev[KAM_TR_INDEX]); err != nil {
return nil, err
}
if _, hasIt := kev[KAM_TR_LABEL]; !hasIt {
- return nil, fmt.Errorf("%s:%s", utils.ERR_MANDATORY_IE_MISSING, KAM_TR_LABEL)
+ return nil, utils.NewErrMandatoryIeMissing(KAM_TR_LABEL, "")
}
if kar.TransactionLabel, err = strconv.Atoi(kev[KAM_TR_LABEL]); err != nil {
return nil, err
diff --git a/sessionmanager/osipssm.go b/sessionmanager/osipssm.go
index 6b05f64bb..8762c7ed0 100644
--- a/sessionmanager/osipssm.go
+++ b/sessionmanager/osipssm.go
@@ -268,10 +268,10 @@ func (osm *OsipsSessionManager) onAccEvent(osipsDgram *osipsdagram.OsipsEvent) {
// Handler of call start event. Mostly starts a session if needed
func (osm *OsipsSessionManager) callStart(osipsEv *OsipsEvent) error {
if osipsEv.MissingParameter() {
- if err := osm.DisconnectSession(osipsEv, "", utils.ERR_MANDATORY_IE_MISSING); err != nil {
+ if err := osm.DisconnectSession(osipsEv, "", utils.ErrMandatoryIeMissing.Error()); err != nil {
return err
}
- return errors.New(utils.ERR_MANDATORY_IE_MISSING)
+ return utils.ErrMandatoryIeMissing
}
s := NewSession(osipsEv, "", osm)
if s != nil {
@@ -292,7 +292,7 @@ func (osm *OsipsSessionManager) callEnd(osipsEv *OsipsEvent) error {
return err
}
if origEvent.MissingParameter() {
- return errors.New(utils.ERR_MANDATORY_IE_MISSING)
+ return utils.ErrMandatoryIeMissing
}
if err := s.Close(origEvent); err != nil { // Stop loop, refund advanced charges and save the costs deducted so far to database
return err
diff --git a/sessionmanager/session.go b/sessionmanager/session.go
index e2454c445..53b00e423 100644
--- a/sessionmanager/session.go
+++ b/sessionmanager/session.go
@@ -20,7 +20,6 @@ package sessionmanager
import (
"encoding/json"
- "errors"
"fmt"
"time"
@@ -232,7 +231,7 @@ func (s *Session) SaveOperations() {
// when the cdr arrives to cdrserver because our callcost is not there it will be rated
// as postpaid. When the close event finally arives we have to refund everything
if err != nil {
- if err == errors.New(utils.ERR_EXISTS) {
+ if err == utils.ErrExists {
s.Refund(firstCC, firstCC.Timespans[0].TimeStart)
} else {
engine.Logger.Err(fmt.Sprintf("failed to log call cost: %v", err))
diff --git a/utils/consts.go b/utils/consts.go
index f154213d3..1c688c31a 100644
--- a/utils/consts.go
+++ b/utils/consts.go
@@ -1,5 +1,29 @@
package utils
+import (
+ "errors"
+ "fmt"
+)
+
+func NewErrMandatoryIeMissing(fields ...string) error {
+ return fmt.Errorf("MANDATORY_IE_MISSING:%v", fields)
+}
+
+func NewErrServerError(err error) error {
+ return fmt.Errorf("SERVER_ERROR: %s", err)
+}
+
+var (
+ ErrNotImplemented = errors.New("NOT_IMPLEMENTED")
+ ErrNotFound = errors.New("NOT_FOUND")
+ ErrServerError = errors.New("SERVER_ERROR")
+ ErrMandatoryIeMissing = errors.New("MANDATORY_IE_MISSING")
+ ErrExists = errors.New("EXISTS")
+ ErrBrokenReference = errors.New("BROKEN_REFERENCE")
+ ErrParserError = errors.New("PARSER_ERROR")
+ ErrInvalidPath = errors.New("INVALID_PATH")
+)
+
const (
VERSION = "0.9.1rc6"
POSTGRES = "postgres"
@@ -20,14 +44,6 @@ const (
META_RATED = "*rated"
META_NONE = "*none"
META_NOW = "*now"
- ERR_NOT_IMPLEMENTED = "NOT_IMPLEMENTED"
- ERR_SERVER_ERROR = "SERVER_ERROR"
- ERR_NOT_FOUND = "NOT_FOUND"
- ERR_MANDATORY_IE_MISSING = "MANDATORY_IE_MISSING"
- ERR_EXISTS = "EXISTS"
- ERR_BROKEN_REFERENCE = "BROKEN_REFERENCE"
- ERR_PARSER_ERROR = "PARSER_ERROR"
- ERR_INVALID_PATH = "INVALID_PATH"
TBL_TP_TIMINGS = "tp_timings"
TBL_TP_DESTINATIONS = "tp_destinations"
TBL_TP_RATES = "tp_rates"