better account disabled error reporting

This commit is contained in:
Radu Ioan Fericean
2016-03-29 23:34:48 +03:00
parent 10054d353a
commit 97c96dd46d

View File

@@ -188,7 +188,11 @@ func (cd *CallDescriptor) getAccount() (ub *Account, err error) {
cd.account, err = accountingStorage.GetAccount(cd.GetAccountKey())
}
if cd.account != nil && cd.account.Disabled {
return nil, fmt.Errorf("User %s is disabled", cd.account.ID)
return nil, utils.ErrAccountDisabled
}
if err != nil || cd.account == nil {
utils.Logger.Warning(fmt.Sprintf("Account: %s, not found (%v)", cd.GetAccountKey(), err))
return nil, utils.ErrAccountNotFound
}
return cd.account, err
}
@@ -635,13 +639,9 @@ func (origCD *CallDescriptor) getMaxSessionDuration(origAcc *Account) (time.Dura
func (cd *CallDescriptor) GetMaxSessionDuration() (duration time.Duration, err error) {
cd.account = nil // make sure it's not cached
if account, err := cd.getAccount(); err != nil || account == nil {
utils.Logger.Err(fmt.Sprintf("Account: %s, not found", cd.GetAccountKey()))
return 0, utils.ErrAccountNotFound
if account, err := cd.getAccount(); err != nil {
return 0, err
} else {
if account.Disabled {
return 0, utils.ErrAccountDisabled
}
if memberIds, err := account.GetUniqueSharedGroupMembers(cd); err == nil {
if _, err := Guardian.Guard(func() (interface{}, error) {
duration, err = cd.getMaxSessionDuration(account)
@@ -705,13 +705,9 @@ func (cd *CallDescriptor) debit(account *Account, dryRun bool, goNegative bool)
func (cd *CallDescriptor) Debit() (cc *CallCost, err error) {
cd.account = nil // make sure it's not cached
// lock all group members
if account, err := cd.getAccount(); err != nil || account == nil {
utils.Logger.Err(fmt.Sprintf("Account: %s, not found", cd.GetAccountKey()))
return nil, utils.ErrAccountNotFound
if account, err := cd.getAccount(); err != nil {
return nil, err
} else {
if account.Disabled {
return nil, utils.ErrAccountDisabled
}
if memberIds, sgerr := account.GetUniqueSharedGroupMembers(cd); sgerr == nil {
_, err = Guardian.Guard(func() (interface{}, error) {
cc, err = cd.debit(account, cd.DryRun, true)
@@ -730,13 +726,9 @@ func (cd *CallDescriptor) Debit() (cc *CallCost, err error) {
// by the GetMaxSessionDuration method. The amount filed has to be filled in call descriptor.
func (cd *CallDescriptor) MaxDebit() (cc *CallCost, err error) {
cd.account = nil // make sure it's not cached
if account, err := cd.getAccount(); err != nil || account == nil {
utils.Logger.Err(fmt.Sprintf("Account: %s, not found", cd.GetAccountKey()))
return nil, utils.ErrAccountNotFound
if account, err := cd.getAccount(); err != nil {
return nil, err
} else {
if account.Disabled {
return nil, utils.ErrAccountDisabled
}
//log.Printf("ACC: %+v", account)
if memberIDs, err := account.GetUniqueSharedGroupMembers(cd); err == nil {
_, err = Guardian.Guard(func() (interface{}, error) {