Skip to content

Commit

Permalink
Handle unknown stickiness value.
Browse files Browse the repository at this point in the history
Co-authored-by: Renato Arruda <git@rarruda.org>
  • Loading branch information
jdurkee-mdsol and rarruda committed May 15, 2023
1 parent e3edcc1 commit 8c9ecd4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/unleash/feature_toggle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ def sum_variant_defs_weights
end

def variant_salt(context, stickiness = "default")
return context.get_by_name(stickiness) if !context.nil? && stickiness != "default"
begin
return context.get_by_name(stickiness) if !context.nil? && stickiness != "default"
rescue KeyError
Unleash.logger.warn "Custom stickiness key (#{stickiness}) not found in the provided context #{context}. " \
"Falling back to default behavior."
end
return context.user_id unless context&.user_id.to_s.empty?
return context.session_id unless context&.session_id.to_s.empty?
return context.remote_address unless context&.remote_address.to_s.empty?
Expand Down

0 comments on commit 8c9ecd4

Please sign in to comment.