newrelic: log with_timeout errors as expected.

Make it so that when a database call inside a `with_timeout` block times
out, the error logged to New Relic is marked as expected. This is so
that expected timeouts, such as timeouts when calculating search counts
or timeouts when generating related tags for the sidebar, don't count
against the error rate.
This commit is contained in:
evazion
2021-10-14 23:39:21 -05:00
parent 7dc885f216
commit 300bc6941e

View File

@@ -136,7 +136,7 @@ class ApplicationRecord < ActiveRecord::Base
connection.execute("SET STATEMENT_TIMEOUT = #{n}") unless Rails.env.test?
yield
rescue ::ActiveRecord::StatementInvalid => e
DanbooruLogger.log(e, expected: false, **new_relic_params)
DanbooruLogger.log(e, expected: true, **new_relic_params)
default_value
ensure
connection.execute("SET STATEMENT_TIMEOUT = #{CurrentUser.user.try(:statement_timeout) || 3_000}") unless Rails.env.test?