Exception: Synthra::Errors::SimulatedError

Inherits:
SimulatedBehaviorError show all
Defined in:
lib/synthra/errors.rb

Overview

Simulated HTTP error

Raised by the @simulate_error behavior to simulate specific HTTP error responses. Useful for testing how applications handle various HTTP status codes.

Examples:

DSL usage

# API:
#   @simulate_error 429:5%  <- 5% chance of 429 Too Many Requests
#   @simulate_error 500:1%  <- 1% chance of 500 Internal Server Error
#   id: uuid

Constant Summary collapse

ERROR_CODE =
"SIMULATED_ERROR"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code:, probability: nil) ⇒ SimulatedError

Create a new SimulatedError

Parameters:

  • code (Integer)

    the HTTP status code to simulate

  • probability (Integer, nil) (defaults to: nil)

    the probability percentage if configured



1099
1100
1101
1102
1103
1104
1105
# File 'lib/synthra/errors.rb', line 1099

def initialize(code:, probability: nil)
  @code = code
  @probability = probability
  message = "Simulated HTTP error: #{code}"
  message += " (#{probability}% probability)" if probability
  super(message)
end

Instance Attribute Details

#codeInteger (readonly)

Returns the HTTP status code being simulated.

Returns:

  • (Integer)

    the HTTP status code being simulated



1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
# File 'lib/synthra/errors.rb', line 1088

class SimulatedError < SimulatedBehaviorError
  ERROR_CODE = "SIMULATED_ERROR"
  attr_reader :code, :probability


  # Create a new SimulatedError
  #
  # @param code [Integer] the HTTP status code to simulate
  # @param probability [Integer, nil] the probability percentage if configured
  #

  def initialize(code:, probability: nil)
    @code = code
    @probability = probability
    message = "Simulated HTTP error: #{code}"
    message += " (#{probability}% probability)" if probability
    super(message)
  end
end

#probabilityInteger? (readonly)

Returns the configured probability percentage.

Returns:

  • (Integer, nil)

    the configured probability percentage



1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
# File 'lib/synthra/errors.rb', line 1088

class SimulatedError < SimulatedBehaviorError
  ERROR_CODE = "SIMULATED_ERROR"
  attr_reader :code, :probability


  # Create a new SimulatedError
  #
  # @param code [Integer] the HTTP status code to simulate
  # @param probability [Integer, nil] the probability percentage if configured
  #

  def initialize(code:, probability: nil)
    @code = code
    @probability = probability
    message = "Simulated HTTP error: #{code}"
    message += " (#{probability}% probability)" if probability
    super(message)
  end
end