Sha256: c2c00305315501c8174255ba24ae3f542187a38626f6e87a062abf8219321e2e

Contents?: true

Size: 832 Bytes

Versions: 3

Compression:

Stored size: 832 Bytes

Contents

module Jortt # :nodoc:
  class Client # :nodoc:
    class Error < StandardError # :nodoc:
      attr_reader :response, :code, :key, :message, :details

      def self.from_response(response)
        Error.new(
            response.parsed.dig('error', 'code'),
            response.parsed.dig('error', 'key'),
            response.parsed.dig('error', 'message'),
            response.parsed.dig('error', 'details')
        )
      end

      def initialize(code, key, message, details)
        @code = code
        @key = key
        @message = message
        @details = details

        super(error_message)
      end

      def error_message
        [message].tap do |m|
          details.each do |detail|
            m << "#{detail['param']} #{detail['message']}"
          end
        end.join("\n")
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
jortt-6.1.0 lib/jortt/client/error.rb
jortt-6.0.0 lib/jortt/client/error.rb
jortt-5.0.0 lib/jortt/client/error.rb