Exception: Lighthouse::LettersGenerator::ServiceError

Inherits:
Common::Exceptions::BaseError show all
Defined in:
lib/lighthouse/letters_generator/service_error.rb

Constant Summary collapse

ERROR_MAP =
{
  400 => 'lighthouse.letters_generator.bad_request',
  401 => 'lighthouse.letters_generator.not_authorized',
  403 => 'lighthouse.letters_generator.forbidden',
  404 => 'lighthouse.letters_generator.not_found',
  406 => 'lighthouse.letters_generator.not_acceptable',
  413 => 'lighthouse.letters_generator.payload_too_large',
  422 => 'lighthouse.letters_generator.unprocessable_entity',
  429 => 'lighthouse.letters_generator.too_many_requests',
  504 => 'lighthouse.letters_generator.gateway_timeout',
  default: 'common.exceptions.internal_server_error'
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Common::Exceptions::BaseError

#i18n_data, #i18n_field, #i18n_interpolated, #log_to_sentry?, #sentry_type, #status_code

Constructor Details

#initialize(exception = nil) ⇒ ServiceError

Expects a response in one of these formats:

{ status: "", title: "", detail: "", type: "", instance: "" }

OR

{ message: "" }


28
29
30
31
32
33
34
35
36
# File 'lib/lighthouse/letters_generator/service_error.rb', line 28

def initialize(exception = nil)
  super
  unless exception.nil?
    @status ||= exception['status'].to_i
    @title ||= exception['title']
    @message = exception['detail'] || exception['message']
  end
  @key ||= error_key
end

Instance Attribute Details

#keyObject

Returns the value of attribute key.



8
9
10
# File 'lib/lighthouse/letters_generator/service_error.rb', line 8

def key
  @key
end

#messageObject

Returns the value of attribute message.



8
9
10
# File 'lib/lighthouse/letters_generator/service_error.rb', line 8

def message
  @message
end

#statusObject

Returns the value of attribute status.



8
9
10
# File 'lib/lighthouse/letters_generator/service_error.rb', line 8

def status
  @status
end

#titleObject

Returns the value of attribute title.



8
9
10
# File 'lib/lighthouse/letters_generator/service_error.rb', line 8

def title
  @title
end

Instance Method Details

#error_keyObject (private)



52
53
54
# File 'lib/lighthouse/letters_generator/service_error.rb', line 52

def error_key
  ERROR_MAP[@status] || ERROR_MAP[:default]
end

#errorsObject



38
39
40
41
42
43
44
# File 'lib/lighthouse/letters_generator/service_error.rb', line 38

def errors
  Array(
    Common::Exceptions::SerializableError.new(
      i18n_data.merge(title: @title, meta: { message: @message }, source: 'Lighthouse::LettersGenerator::Service')
    )
  )
end

#i18n_keyObject (private)



48
49
50
# File 'lib/lighthouse/letters_generator/service_error.rb', line 48

def i18n_key
  @key
end