Sha256: 2c14c42909a9e8dd4b86886bd939a57763cec19ed947ae74717fb6c47d2de0e6

Contents?: true

Size: 1.01 KB

Versions: 49

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

module DjiMqttConnect
  # Represents an Error caused when communicatng via MQTT
  class Error < StandardError
    attr_reader :wrapped_exception

    def initialize(error, message = nil)
      @wrapped_exception, msg = error_and_message(error, message)
      super(msg)
    end

    def backtrace
      if @wrapped_exception
        @wrapped_exception.backtrace
      else
        super
      end
    end

    def inspect
      if @wrapped_exception
        inner = +""
        inner += ": #{message}," if !message.empty? && @wrapped_exception.message != message
        inner << " wrapped=#{@wrapped_exception.inspect}"
        %(#<#{self.class}#{inner}>)
      else
        super
      end
    end

    private

    # Pulls out potential parent exception and response hash.
    def error_and_message(exc, message)
      return [exc, message || exc.message] if exc.respond_to?(:backtrace)

      [nil, exc.to_s]
    end
  end

  # Indicates a problem parsing a response
  class ParseError < Error
  end
end

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
dji_mqtt_connect-0.1.16.2 lib/dji_mqtt_connect/error.rb
dji_mqtt_connect-0.1.16.1 lib/dji_mqtt_connect/error.rb
dji_mqtt_connect-0.1.16 lib/dji_mqtt_connect/error.rb
dji_mqtt_connect-0.1.15.2 lib/dji_mqtt_connect/error.rb
dji_mqtt_connect-0.1.15.1 lib/dji_mqtt_connect/error.rb
dji_mqtt_connect-0.1.15 lib/dji_mqtt_connect/error.rb
dji_mqtt_connect-0.1.14.1 lib/dji_mqtt_connect/error.rb
dji_mqtt_connect-0.1.14 lib/dji_mqtt_connect/error.rb
dji_mqtt_connect-0.1.13.1 lib/dji_mqtt_connect/error.rb
dji_mqtt_connect-0.1.13 lib/dji_mqtt_connect/error.rb
dji_mqtt_connect-0.1.12.1 lib/dji_mqtt_connect/error.rb
dji_mqtt_connect-0.1.12 lib/dji_mqtt_connect/error.rb
dji_mqtt_connect-0.1.11 lib/dji_mqtt_connect/error.rb
dji_mqtt_connect-0.1.10 lib/dji_mqtt_connect/error.rb
dji_mqtt_connect-0.1.9 lib/dji_mqtt_connect/error.rb
dji_mqtt_connect-0.1.8 lib/dji_mqtt_connect/error.rb
dji_mqtt_connect-0.1.7 lib/dji_mqtt_connect/error.rb
dji_mqtt_connect-0.1.6 lib/dji_mqtt_connect/error.rb
dji_mqtt_connect-0.1.5 lib/dji_mqtt_connect/error.rb
dji_mqtt_connect-0.1.4.1 lib/dji_mqtt_connect/error.rb