Class: RailsErrorDashboard::Commands::BatchMuteErrors

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_error_dashboard/commands/batch_mute_errors.rb

Overview

Command: Mute multiple errors at once

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error_ids, muted_by = nil) ⇒ BatchMuteErrors

Returns a new instance of BatchMuteErrors.



11
12
13
14
# File 'lib/rails_error_dashboard/commands/batch_mute_errors.rb', line 11

def initialize(error_ids, muted_by = nil)
  @error_ids = Array(error_ids).compact
  @muted_by = muted_by
end

Class Method Details

.call(error_ids, muted_by: nil) ⇒ Object



7
8
9
# File 'lib/rails_error_dashboard/commands/batch_mute_errors.rb', line 7

def self.call(error_ids, muted_by: nil)
  new(error_ids, muted_by).call
end

Instance Method Details

#callObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rails_error_dashboard/commands/batch_mute_errors.rb', line 16

def call
  return { success: false, count: 0, errors: [ "No error IDs provided" ] } if @error_ids.empty?

  errors = ErrorLog.where(id: @error_ids)

  muted_count = 0
  failed_ids = []
  muted_errors = []

  errors.each do |error|
    begin
      error.update!(
        muted: true,
        muted_at: Time.current,
        muted_by: @muted_by
      )
      muted_count += 1
      muted_errors << error
    rescue => e
      failed_ids << error.id
      RailsErrorDashboard::Logger.error("Failed to mute error #{error.id}: #{e.message}")
    end
  end

  PluginRegistry.dispatch(:on_errors_batch_muted, muted_errors) if muted_errors.any?

  {
    success: failed_ids.empty?,
    count: muted_count,
    total: @error_ids.size,
    failed_ids: failed_ids,
    errors: failed_ids.empty? ? [] : [ "Failed to mute #{failed_ids.size} error(s)" ]
  }
rescue => e
  RailsErrorDashboard::Logger.error("Batch mute failed: #{e.message}")
  { success: false, count: 0, total: @error_ids.size, errors: [ e.message ] }
end