Sha256: 6d8f5283f35f444e2228530e9c3f8e03940df88e8536bd69588bdf52c4662d44

Contents?: true

Size: 427 Bytes

Versions: 3

Compression:

Stored size: 427 Bytes

Contents

module Notifications
  class Client
    class RequestError < StandardError
      attr_reader :code, :message

      def initialize(response)
        @code = response.code
        @message = message_from(response.body)
      end

      def to_s
        "#{code} #{message}"
      end

      def message_from(body)
        JSON.parse(body).fetch("message")
      rescue JSON::ParserError
        body
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
notifications-ruby-client-1.1.2 lib/notifications/client/request_error.rb
notifications-ruby-client-1.1.1 lib/notifications/client/request_error.rb
notifications-ruby-client-1.0.0 lib/notifications/client/request_error.rb