blob: faabddd2686801d228e0d06f339c36c9e1e204cb (
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
40
41
|
# frozen_string_literal: true
module ActiveRecord
module GitlabPatches
# This adds `rescue_from` to ActiveRecord::Base.
# Currently only the following places will be handled by `rescue_from`:
#
# - `ActiveRecord::Relation#load`, and other methods that call
# `ActiveRecord::Relation#exec_queries`.
#
# 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
|