class Lurch::Errors::JSONApiError

Attributes

status[R]

Public Class Methods

new(document, status) click to toggle source
# File lib/lurch/errors/json_api_error.rb, line 6
def initialize(document, status)
  @document = document
  @status = status
end

Public Instance Methods

errors() click to toggle source
# File lib/lurch/errors/json_api_error.rb, line 17
def errors
  return [] unless errors_document?

  @document["errors"].map { |error| Lurch::Error.new(error) }
end
message() click to toggle source
# File lib/lurch/errors/json_api_error.rb, line 11
def message
  return "#{@status}: #{@document}" unless errors_document?

  "#{@status}: #{errors_string}"
end

Private Instance Methods

errors_document?() click to toggle source
# File lib/lurch/errors/json_api_error.rb, line 25
def errors_document?
  @document.is_a?(Hash) && @document["errors"].is_a?(Array)
end
errors_string() click to toggle source
# File lib/lurch/errors/json_api_error.rb, line 29
def errors_string
  @document["errors"].map { |error| error["detail"] }.join(", ")
end