Exception: Beaneater::UnexpectedResponse

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/beaneater/errors.rb

Overview

Abstract class for errors that occur when a command does not complete successfully.

Constant Summary collapse

ERROR_STATES =

Set of status states that are considered errors

%w(OUT_OF_MEMORY INTERNAL_ERROR
BAD_FORMAT UNKNOWN_COMMAND JOB_TOO_BIG DRAINING
TIMED_OUT DEADLINE_SOON NOT_FOUND NOT_IGNORED EXPECTED_CRLF)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status, cmd) ⇒ UnexpectedResponse

Initialize unexpected response error

Examples:

Beaneater::UnexpectedResponse.new(NotFoundError, 'bury 123')

Parameters:


32
33
34
35
# File 'lib/beaneater/errors.rb', line 32

def initialize(status, cmd)
  @status, @cmd = status, cmd
  super("Response failed with: #{status}")
end

Instance Attribute Details

#cmdObject

Returns the value of attribute cmd


22
# File 'lib/beaneater/errors.rb', line 22

attr_reader :status, :cmd

#statusString

Returns beanstalkd response status

Examples:

@ex.status # => "NOT_FOUND"

Returns:

  • (String)

    returns beanstalkd response status


22
23
24
# File 'lib/beaneater/errors.rb', line 22

def status
  @status
end

Class Method Details

.from_status(status, cmd) ⇒ Beaneater::UnexpectedResponse

Translate beanstalkd error status to ruby Exeception

Examples:

Beaneater::UnexpectedResponse.new('NOT_FOUND', 'bury 123')

Parameters:

  • status (String)

    Beanstalkd error status

  • cmd (String)

    Beanstalkd request command

Returns:


46
47
48
49
50
51
# File 'lib/beaneater/errors.rb', line 46

def self.from_status(status, cmd)
  error_klazz_name = status.split('_').map { |w| w.capitalize }.join
  error_klazz_name << "Error" unless error_klazz_name =~ /Error$/
  error_klazz = Beaneater.const_get(error_klazz_name)
  error_klazz.new(status, cmd)
end