Class: RailsErrorDashboard::Commands::BatchUnmuteErrors

Inherits:
Object
  • Object
show all
Includes:
Translation
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

Methods included from Translation

#red_locale, #red_t, #red_tp

Constructor Details

#initialize(error_ids) ⇒ BatchUnmuteErrors

Returns a new instance of BatchUnmuteErrors.



13
14
15
# File 'lib/rails_error_dashboard/commands/batch_unmute_errors.rb', line 13

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

Class Method Details

.call(error_ids) ⇒ Object



9
10
11
# File 'lib/rails_error_dashboard/commands/batch_unmute_errors.rb', line 9

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

Instance Method Details

#callObject



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
53
54
# File 'lib/rails_error_dashboard/commands/batch_unmute_errors.rb', line 17

def call
  return { success: false, count: 0, errors: [ red_t("red.commands.no_error_ids") ] } 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? ? [] : [ red_tp("red.commands.batch_failed.unmute", count: failed_ids.size) ]
  }
rescue => e
  RailsErrorDashboard::Logger.error("Batch unmute failed: #{e.message}")
  { success: false, count: 0, total: @error_ids.size, errors: [ e.message ] }
end