Sha256: 24ab2d1b4e28c3dc1224c33d53ccbb80358636a3eec6697649a96f89f0aebe89

Contents?: true

Size: 1 KB

Versions: 5

Compression:

Stored size: 1 KB

Contents

module FlexCommerceApi
  module Error
    class InternalServer < Base
      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

      def raven_context
        {
          extra: {
            body: response_env[:body]
          }  
        }
      end

      private

      def extract_error(body)
        return body if body.is_a?(::String)
        body["message"] || body["errors"]&.first
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
flex_commerce_api-0.8.3 lib/flex_commerce_api/error/internal_server.rb
flex_commerce_api-0.8.2 lib/flex_commerce_api/error/internal_server.rb
flex_commerce_api-0.8.1 lib/flex_commerce_api/error/internal_server.rb
flex_commerce_api-0.7 lib/flex_commerce_api/error/internal_server.rb
flex_commerce_api-0.6.57 lib/flex_commerce_api/error/internal_server.rb