Exception: Lighthouse::LettersGenerator::ServiceError
- Inherits:
-
Common::Exceptions::BaseError
- Object
- StandardError
- Common::Exceptions::BaseError
- Lighthouse::LettersGenerator::ServiceError
- 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
-
#key ⇒ Object
Returns the value of attribute key.
-
#message ⇒ Object
Returns the value of attribute message.
-
#status ⇒ Object
Returns the value of attribute status.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #error_key ⇒ Object private
- #errors ⇒ Object
- #i18n_key ⇒ Object private
-
#initialize(exception = nil) ⇒ ServiceError
constructor
Expects a response in one of these formats: { status: “”, title: “”, detail: “”, type: “”, instance: “” } OR { message: “” }.
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
#key ⇒ Object
Returns the value of attribute key.
8 9 10 |
# File 'lib/lighthouse/letters_generator/service_error.rb', line 8 def key @key end |
#message ⇒ Object
Returns the value of attribute message.
8 9 10 |
# File 'lib/lighthouse/letters_generator/service_error.rb', line 8 def @message end |
#status ⇒ Object
Returns the value of attribute status.
8 9 10 |
# File 'lib/lighthouse/letters_generator/service_error.rb', line 8 def status @status end |
#title ⇒ Object
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_key ⇒ Object (private)
52 53 54 |
# File 'lib/lighthouse/letters_generator/service_error.rb', line 52 def error_key ERROR_MAP[@status] || ERROR_MAP[:default] end |
#errors ⇒ Object
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_key ⇒ Object (private)
48 49 50 |
# File 'lib/lighthouse/letters_generator/service_error.rb', line 48 def i18n_key @key end |