Sha256: cf9b31026b451602ce5ef0fd45595b73138b79a9b358aa8de94bdf01f79d5c76

Contents?: true

Size: 788 Bytes

Versions: 12

Compression:

Stored size: 788 Bytes

Contents

# frozen_string_literal: true

module Rabbit::Receiving
  class MalformedMessage < StandardError
    attr_accessor :message_model, :errors

    def self.logger
      @logger ||= Rabbit.config.malformed_logger
    end

    def self.raise!(message_model, errors, backtrace = caller(1))
      error = new(message_model, errors)
      logger.error error.message
      raise error, error.message, backtrace
    end

    def initialize(message_model, errors)
      self.message_model = message_model
      self.errors = Array(errors)

      errors_list = Array(errors).map { |e| "  - #{e}" }.join("\n")

      super(<<~MESSAGE)
        Malformed message rejected for following reasons:
        #{errors_list}
        Message: #{message_model.attributes.inspect}
      MESSAGE
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rabbit_messaging-1.1.0 lib/rabbit/receiving/malformed_message.rb
rabbit_messaging-1.0.0 lib/rabbit/receiving/malformed_message.rb
rabbit_messaging-0.15.0 lib/rabbit/receiving/malformed_message.rb
rabbit_messaging-0.13.0 lib/rabbit/receiving/malformed_message.rb
rabbit_messaging-0.12.1 lib/rabbit/receiving/malformed_message.rb
rabbit_messaging-0.12.0 lib/rabbit/receiving/malformed_message.rb
rabbit_messaging-0.11.0 lib/rabbit/receiving/malformed_message.rb
rabbit_messaging-0.10.0 lib/rabbit/receiving/malformed_message.rb
rabbit_messaging-0.9.0 lib/rabbit/receiving/malformed_message.rb
rabbit_messaging-0.8.1 lib/rabbit/receiving/malformed_message.rb
rabbit_messaging-0.7.1 lib/rabbit/receiving/malformed_message.rb
rabbit_messaging-0.7.0 lib/rabbit/receiving/malformed_message.rb