# 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, user_agent: request.user_agent || "", } # 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, version: Websites.config.full_version, extra_params: extra_params, ) end end