Skip to content

Commit

Permalink
Pass SQL to ResponseProcessor for logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
leboshi committed Nov 23, 2024
1 parent dade0fa commit a65dffb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def formatted_sql
end

def processed_response
ResponseProcessor.new(@response, @format).process
ResponseProcessor.new(@response, @format, @sql).process
end

end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ class ResponseProcessor

DB_EXCEPTION_REGEXP = /\ACode:\s+\d+\.\s+DB::Exception:/.freeze

def initialize(raw_response, format)
def initialize(raw_response, format, sql)
@raw_response = raw_response
@body = raw_response.body
@format = format
@sql = sql
end

def process
Expand All @@ -31,13 +32,13 @@ def success?
end

def process_successful_response
raise_generic! if @body.include?('DB::Exception') && @body.match?(DB_EXCEPTION_REGEXP)
raise_generic!(@sql) if @body.include?('DB::Exception') && @body.match?(DB_EXCEPTION_REGEXP)

format_body_response
end

def raise_generic!
raise ActiveRecord::ActiveRecordError, "Response code: #{@raw_response.code}:\n#{@body}"
def raise_generic!(sql = nil)
raise ActiveRecord::ActiveRecordError, "Response code: #{@raw_response.code}:\n#{@body}#{"\nQuery: #{sql}" if sql}"
end

def format_body_response
Expand Down

0 comments on commit a65dffb

Please sign in to comment.