mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Return nil instead of NOT_FOUND if no opts pass the filters
This commit is contained in:
committed by
Dan Christian Bogos
parent
ecdf5e54ea
commit
4fb2f7dc0b
@@ -262,7 +262,7 @@ func GetIntPointerOpts(ctx *context.Context, tnt string, ev *utils.CGREvent, fS
|
||||
return opt.Value, nil
|
||||
}
|
||||
}
|
||||
return nil, utils.ErrNotFound // return NOT_FOUND if there are no options and none of the filters pass
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// GetDurationPointerOptsFromMultipleMaps checks the specified option names in order among the keys in APIOpts, then in startOpts, returning the first value it finds as *time.Duration,
|
||||
@@ -295,7 +295,7 @@ func GetDurationPointerOptsFromMultipleMaps(ctx *context.Context, tnt string, ev
|
||||
return opt.Value, nil
|
||||
}
|
||||
}
|
||||
return nil, utils.ErrNotFound // return NOT_FOUND if there are no options and none of the filters pass
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// GetDurationOptsFromMultipleMaps checks the specified option names in order among the keys in APIOpts, then in startOpts, returning the first value it finds as time.Duration,
|
||||
|
||||
@@ -1367,7 +1367,7 @@ func TestLibFiltersGetIntPointerOptsFilterCheckErr(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestLibFiltersGetIntPointerOptsErrNotFound(t *testing.T) {
|
||||
func TestLibFiltersGetIntPointerOptsReturnDft(t *testing.T) {
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
dataDB := NewInternalDB(nil, nil, nil)
|
||||
dm := NewDataManager(dataDB, cfg.CacheCfg(), nil)
|
||||
@@ -1390,8 +1390,8 @@ func TestLibFiltersGetIntPointerOptsErrNotFound(t *testing.T) {
|
||||
}
|
||||
|
||||
if _, err := GetIntPointerOpts(context.Background(), "cgrates.org", ev, fS, dynOpts,
|
||||
utils.OptsRoutesProfilesCount); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ErrNotFound, err)
|
||||
utils.OptsRoutesProfilesCount); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1740,7 +1740,7 @@ func TestLibFiltersGetDurationPointerOptsFromMultipleMapsFilterCheckErr(t *testi
|
||||
}
|
||||
}
|
||||
|
||||
func TestLibFiltersGetDurationPointerOptsFromMultipleMapsErrNotFound(t *testing.T) {
|
||||
func TestLibFiltersGetDurationPointerOptsFromMultipleMapsReturnDft(t *testing.T) {
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
dataDB := NewInternalDB(nil, nil, nil)
|
||||
dm := NewDataManager(dataDB, cfg.CacheCfg(), nil)
|
||||
@@ -1760,8 +1760,8 @@ func TestLibFiltersGetDurationPointerOptsFromMultipleMapsErrNotFound(t *testing.
|
||||
}
|
||||
|
||||
if _, err := GetDurationPointerOptsFromMultipleMaps(context.Background(), "cgrates.org", eventStart, apiOpts, startOpts, fS, dynOpts,
|
||||
utils.OptsSesTTLUsage); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ErrNotFound, err)
|
||||
utils.OptsSesTTLUsage); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -243,34 +243,28 @@ func (sS *SessionS) setSTerminator(ctx *context.Context, s *Session, opts engine
|
||||
var ttlLastUsed *time.Duration
|
||||
if ttlLastUsed, err = engine.GetDurationPointerOptsFromMultipleMaps(ctx, s.Tenant, s.EventStart, opts, s.OptsStart, sS.fltrS,
|
||||
sS.cfg.SessionSCfg().Opts.TTLLastUsed, utils.OptsSesTTLLastUsed); err != nil {
|
||||
if err != utils.ErrNotFound {
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<%s>, cannot extract <%s> for session:<%s>, from its options: <%s>, err: <%s>",
|
||||
utils.SessionS, utils.OptsSesTTLLastUsed, s.OptsStart[utils.MetaOriginID], opts.String(), err.Error()))
|
||||
return
|
||||
}
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<%s>, cannot extract <%s> for session:<%s>, from its options: <%s>, err: <%s>",
|
||||
utils.SessionS, utils.OptsSesTTLLastUsed, s.OptsStart[utils.MetaOriginID], opts.String(), err.Error()))
|
||||
return
|
||||
}
|
||||
// LastUsage
|
||||
var ttlLastUsage *time.Duration
|
||||
if ttlLastUsage, err = engine.GetDurationPointerOptsFromMultipleMaps(ctx, s.Tenant, s.EventStart, opts, s.OptsStart, sS.fltrS,
|
||||
sS.cfg.SessionSCfg().Opts.TTLLastUsage, utils.OptsSesTTLLastUsage); err != nil {
|
||||
if err != utils.ErrNotFound {
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<%s>, cannot extract <%s> for session:<%s>, from its options: <%s>, err: <%s>",
|
||||
utils.SessionS, utils.OptsSesTTLLastUsage, s.OptsStart[utils.MetaOriginID], opts.String(), err.Error()))
|
||||
return
|
||||
}
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<%s>, cannot extract <%s> for session:<%s>, from its options: <%s>, err: <%s>",
|
||||
utils.SessionS, utils.OptsSesTTLLastUsage, s.OptsStart[utils.MetaOriginID], opts.String(), err.Error()))
|
||||
return
|
||||
}
|
||||
// TTLUsage
|
||||
var ttlUsage *time.Duration
|
||||
if ttlUsage, err = engine.GetDurationPointerOptsFromMultipleMaps(ctx, s.Tenant, s.EventStart, opts, s.OptsStart, sS.fltrS,
|
||||
sS.cfg.SessionSCfg().Opts.TTLUsage, utils.OptsSesTTLUsage); err != nil {
|
||||
if err != utils.ErrNotFound {
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<%s>, cannot extract <%s> for session:<%s>, from its options: <%s>, err: <%s>",
|
||||
utils.SessionS, utils.OptsSesTTLUsage, s.OptsStart[utils.MetaOriginID], opts.String(), err.Error()))
|
||||
return
|
||||
}
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<%s>, cannot extract <%s> for session:<%s>, from its options: <%s>, err: <%s>",
|
||||
utils.SessionS, utils.OptsSesTTLUsage, s.OptsStart[utils.MetaOriginID], opts.String(), err.Error()))
|
||||
return
|
||||
}
|
||||
// previously defined, reset
|
||||
if s.sTerminator != nil {
|
||||
|
||||
Reference in New Issue
Block a user