Exception: EsiErrors::Base

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

Constant Summary collapse

PAUSE_DURATION_VALUE =
60
RETRY =
false

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.dispatch(exception, debug_mode: false) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/errors/base.rb', line 10

def self.dispatch( exception, debug_mode: false )

  # return EsiErrors::SocketError.new if exception.message =~ /SocketError/

  puts "EsiErrors::Base got exception : #{exception.inspect}" if debug_mode

  case exception.message

    when '500 Internal Server Error'
      error = EsiErrors::GatewayTimeout.new
    when '504 Gateway Timeout', '504 Gateway Time-out'
      error = EsiErrors::GatewayTimeout.new
    when '502 Bad Gateway'
      error = EsiErrors::BadGateway.new
    when '403 Forbidden'
      error = EsiErrors::Forbidden.new
    when '420 status code 420'
      error = EsiErrors::ErrorLimited.new
    when '404 Not Found'
      error = EsiErrors::NotFound.new
    when 'Net::OpenTimeout'
      error = EsiErrors::OpenTimeout.new
    when 'SocketError'
      error = EsiErrors::SocketError.new
    when '503 Service Unavailable'
      error = EsiErrors::ServiceUnavailable.new
    when '520 status code 520'
      error = EsiErrors::UnknownError.new
    else
      puts exception.full_message
      # pp exception.backtrace_locations
      raise 'Unhandled error'
  end

  if debug_mode
    puts "EsiErrors::Base about to return : #{error.inspect}"
    puts "EsiErrors::Base : retry = #{error.retry?}"
  end

  error
end

Instance Method Details

#pause(test_mode: false) ⇒ Object



56
57
58
# File 'lib/errors/base.rb', line 56

def pause(  test_mode: false )
  sleep( self.class::PAUSE_DURATION_VALUE ) unless test_mode
end

#retry?Boolean



52
53
54
# File 'lib/errors/base.rb', line 52

def retry?
  self.class::RETRY
end