Sha256: 17d0b4b62a9d370a03286238b776d036aa934a0192bb278d461256e182b64345

Contents?: true

Size: 818 Bytes

Versions: 1

Compression:

Stored size: 818 Bytes

Contents

# frozen_string_literal: true

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

    def self.logger
      @logger ||= Logger.new(Rails.root.join("log", "malformed_messages.log"))
    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

1 entries across 1 versions & 1 rubygems

Version Path
rabbit_messaging-0.6.0 lib/rabbit/receiving/malformed_message.rb