Class: YmlErrorResponder::ErrorHandlers::BaseErrorHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/yml_error_responder/error_handlers/base_error_handler.rb

Direct Known Subclasses

DefaultErrorHandler, UnknowErrorHandler

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error, handler_data) ⇒ BaseErrorHandler

Returns a new instance of BaseErrorHandler.



6
7
8
9
# File 'lib/yml_error_responder/error_handlers/base_error_handler.rb', line 6

def initialize(error, handler_data)
  @handler_data = handler_data
  @error = error
end

Instance Attribute Details

#errorObject

Returns the value of attribute error.



4
5
6
# File 'lib/yml_error_responder/error_handlers/base_error_handler.rb', line 4

def error
  @error
end

#handler_dataObject

Returns the value of attribute handler_data.



4
5
6
# File 'lib/yml_error_responder/error_handlers/base_error_handler.rb', line 4

def handler_data
  @handler_data
end

Instance Method Details

#as_jsonObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/yml_error_responder/error_handlers/base_error_handler.rb', line 19

def as_json
  {
    data: {
      error: {
        code: @handler_data[:error_code],
        description: @handler_data[:description]
      },
      meta: meta
    }
  }
end

#http_codeObject



11
12
13
# File 'lib/yml_error_responder/error_handlers/base_error_handler.rb', line 11

def http_code
  @handler_data[:http_code]
end

#metaObject



15
16
17
# File 'lib/yml_error_responder/error_handlers/base_error_handler.rb', line 15

def meta
  @error.try(:meta) || {}
end