Class: Synthra::Behaviors::SimulateError
- Defined in:
- lib/synthra/behaviors/simulate_error.rb
Overview
Simulate error behavior - raises HTTP-like error
Raises SimulatedError exception with a specified HTTP status code when activated, simulating API errors.
Instance Method Summary collapse
-
#apply(result, context = nil) ⇒ Object
Apply simulate error behavior.
-
#extract_code ⇒ Integer
private
Extract error code from value.
Constructor Details
This class inherits a constructor from Synthra::Behaviors::Base
Instance Method Details
#apply(result, context = nil) ⇒ Object
Apply simulate error behavior
Raises SimulatedError if the behavior should be applied based on probability.
50 51 52 53 54 55 56 57 |
# File 'lib/synthra/behaviors/simulate_error.rb', line 50 def apply(result, context = nil) if should_apply? code = extract_code probability = extract_probability raise SimulatedError.new(code: code, probability: probability) end result end |
#extract_code ⇒ Integer (private)
Extract error code from value
Extracts the HTTP status code from the behavior value configuration.
69 70 71 72 73 74 75 |
# File 'lib/synthra/behaviors/simulate_error.rb', line 69 def extract_code case value when Integer then value when Hash then value[:code] || 500 else 500 end end |