Class: RailsErrorDashboard::Commands::BatchUnmuteErrors

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

Overview

Command: Unmute multiple errors at once

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error_ids) ⇒ BatchUnmuteErrors

Returns a new instance of BatchUnmuteErrors.



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

def initialize(error_ids)
  @error_ids = Array(error_ids).compact
end

Class Method Details

.call(error_ids) ⇒ Object



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

def self.call(error_ids)
  new(error_ids).call
end

Instance Method Details

#callObject



15
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_unmute_errors.rb', line 15

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

  errors = ErrorLog.where(id: @error_ids)

  unmuted_count = 0
  failed_ids = []
  unmuted_errors = []

  errors.each do |error|
    begin
      error.update!(
        muted: false,
        muted_at: nil,
        muted_by: nil,
        muted_reason: nil
      )
      unmuted_count += 1
      unmuted_errors << error
    rescue => e
      failed_ids << error.id
      RailsErrorDashboard::Logger.error("Failed to unmute error #{error.id}: #{e.message}")
    end
  end

  PluginRegistry.dispatch(:on_errors_batch_unmuted, unmuted_errors) if unmuted_errors.any?

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