class FunWithJsonApi::Exception
Attributes
payload[R]
Public Class Methods
new(message, payload)
click to toggle source
Calls superclass method
# File lib/fun_with_json_api/exception.rb, line 7 def initialize(message, payload) super(message) @payload = Array.wrap(payload) end
Public Instance Methods
http_status()
click to toggle source
@return [Integer] The http status code for rendering this error
# File lib/fun_with_json_api/exception.rb, line 13 def http_status payload_statuses = payload.map(&:status).uniq if payload_statuses.length == 1 Integer(payload_statuses.first || '400') # Return the unique status code elsif payload_statuses.any? { |status| status.starts_with?('5') } 500 # We have a server error else 400 # Bad Request end end