Diameter.ProcessCDR enforcing usage 0 if errors coming from RALs

This commit is contained in:
DanB
2018-06-08 17:10:20 +02:00
parent dde4991d4e
commit d269bd809e
2 changed files with 14 additions and 3 deletions

View File

@@ -180,8 +180,10 @@ func (da DiameterAgent) processCCR(ccr *CCR, reqProcessor *config.DARequestProce
var evntRply sessions.V1ProcessEventReply
err = da.sessionS.Call(utils.SessionSv1ProcessEvent,
procVars.asV1ProcessEventArgs(cgrEv), &evntRply)
if evntRply.MaxUsage != nil && *evntRply.MaxUsage == 0 {
cgrEv.Event[utils.Usage] = 0 // prevent CDR to be written
if utils.ErrHasPrefix(err, utils.RalsErrorPrfx) {
cgrEv.Event[utils.Usage] = 0 // avoid further debits
} else if evntRply.MaxUsage != nil {
cgrEv.Event[utils.Usage] = *evntRply.MaxUsage // make sure the CDR reflects the debit
}
if procVars[utils.MetaCGRReply], err = utils.NewCGRReply(&evntRply, err); err != nil {
return

View File

@@ -21,6 +21,7 @@ package utils
import (
"errors"
"fmt"
"strings"
)
var (
@@ -54,6 +55,7 @@ var (
ErrNotConvertibleNoCaps = errors.New("not convertible")
ErrMandatoryIeMissingNoCaps = errors.New("mandatory information missing")
ErrUnauthorizedApi = errors.New("UNAUTHORIZED_API")
RalsErrorPrfx = "RALS_ERROR"
)
// NewCGRError initialises a new CGRError
@@ -109,7 +111,7 @@ func NewErrNotConnected(serv string) error {
}
func NewErrRALs(err error) error {
return fmt.Errorf("RALS_ERROR:%s", err)
return fmt.Errorf("%s:%s", RalsErrorPrfx, err)
}
func NewErrResourceS(err error) error {
@@ -141,3 +143,10 @@ func APIErrorHandler(errIn error) (err error) {
func NewErrStringCast(valIface interface{}) error {
return fmt.Errorf("cannot cast value: %v to string", valIface)
}
func ErrHasPrefix(err error, prfx string) (has bool) {
if err == nil {
return
}
return strings.HasPrefix(err.Error(), prfx)
}