blob: eaa42d1523d88146bcf0df2f12891d1499c9bacd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
|
# frozen_string_literal: true
module ActiveRecord
module GitlabPatches
# This adds `rescue_from` to ActiveRecord::Base.
# Currently, only errors called from `ActiveRecord::Relation#exec_queries`
# will be handled by `rescue_from`.
#
# class ApplicationRecord < ActiveRecord::Base
# rescue_from MyException, with: :my_handler
#
# def my_handler(exception)
# Rails.logger.info exception.message
#
# raise exception
# end
# end
module RescueFrom
extend ActiveSupport::Concern
prepended do |base|
base.include ActiveSupport::Rescuable
end
end
module ExecQueriesRescueWithHandler
def exec_queries
super
rescue StandardError => e
klass.rescue_with_handler(e) || raise
end
end
end
end
ActiveSupport.on_load(:active_record) do
ActiveRecord::Relation.prepend(ActiveRecord::GitlabPatches::ExecQueriesRescueWithHandler)
ActiveRecord::Base.prepend(ActiveRecord::GitlabPatches::RescueFrom)
end
|