Websites/app/models/exception_log.rb

35 lines
1.1 KiB
Ruby
Raw Normal View History

2024-05-03 03:04:43 +00:00
# frozen_string_literal: true
class ExceptionLog < ApplicationRecord
serialize :extra_params, coder: JSON
def self.add(exception, request)
extra_params = {
host: Socket.gethostname,
params: request.filtered_parameters,
referrer: request.referrer,
2024-06-11 07:20:34 +00:00
user_agent: request.user_agent || "",
2024-05-03 03:04:43 +00:00
}
# Required to unwrap exceptions that occur inside template rendering.
unwrapped_exception = exception
unwrapped_exception = exception.cause if exception.is_a?(ActionView::Template::Error)
if unwrapped_exception.is_a?(ActiveRecord::QueryCanceled)
extra_params[:sql] = {}
extra_params[:sql][:query] = unwrapped_exception.sql || "[NOT FOUND?]"
extra_params[:sql][:binds] = unwrapped_exception.binds
end
create!(
ip_addr: request.remote_ip || "0.0.0.0",
class_name: unwrapped_exception.class.name,
message: unwrapped_exception.message,
trace: unwrapped_exception.backtrace.join("\n"),
code: SecureRandom.uuid,
2024-08-06 10:28:38 +00:00
version: Websites.config.full_version,
2024-05-03 03:04:43 +00:00
extra_params: extra_params,
)
end
end