class FlexCommerceApi::Error::InternalServer

Public Instance Methods

message() click to toggle source
# File lib/flex_commerce_api/error/internal_server.rb, line 4
def message
  body = response_env.fetch(:body, {"errors" => []})
  error = extract_error(body)
  return "Internal server error" unless error.present?
  if error.is_a?(::Enumerable)
    title = error.fetch("title", "")
    detail = error.fetch("detail", "")
    meta = error.fetch("meta", {})
    exception = meta.fetch("exception", "")
    backtrace = meta.fetch("backtrace", [])
    event_id = meta.fetch("event_id", "")
    "Internal server error - #{title} #{detail} #{event_id} #{exception} #{backtrace}"
  else
    "Internal server error - #{error}"
  end
end
raven_context() click to toggle source
# File lib/flex_commerce_api/error/internal_server.rb, line 21
def raven_context
  {
    extra: {
      body: response_env[:body]
    }  
  }
end

Private Instance Methods

extract_error(body) click to toggle source
# File lib/flex_commerce_api/error/internal_server.rb, line 31
def extract_error(body)
  return body if body.is_a?(::String)
  body["message"] || body["errors"]&.first
end