Class: ErrorExchange

Inherits:
Object
  • Object
show all
Defined in:
app/models/error_exchange.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identifier, status, extra_info = nil) ⇒ ErrorExchange


5
6
7
8
9
# File 'app/models/error_exchange.rb', line 5

def initialize(identifier, status, extra_info = nil)
  @identifier = identifier
  @status     = status
  @extra_info = extra_info
end

Instance Attribute Details

#identifierObject (readonly)

Returns the value of attribute identifier


3
4
5
# File 'app/models/error_exchange.rb', line 3

def identifier
  @identifier
end

#statusObject (readonly)

Returns the value of attribute status


3
4
5
# File 'app/models/error_exchange.rb', line 3

def status
  @status
end

Instance Method Details

#as_jsonObject


11
12
13
14
15
16
17
18
19
20
# File 'app/models/error_exchange.rb', line 11

def as_json(*)
  hash = {
      status: Rack::Utils.status_code(status),
      code: identifier,
      title: translated_payload[:title],
      detail: translated_payload[:detail],
  }
  hash[:extra_info] = @extra_info if @extra_info
  hash
end

#translated_payloadObject


22
23
24
# File 'app/models/error_exchange.rb', line 22

def translated_payload
  I18n.translate("errors.#{identifier}")
end