Skip to content

Commit

Permalink
Update SourceWrapperNotFoundError handling
Browse files Browse the repository at this point in the history
  • Loading branch information
unoduetre committed Jun 24, 2024
1 parent f7839c8 commit d0d7d38
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
12 changes: 11 additions & 1 deletion lib/slimmer/processors/body_inserter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,17 @@ def filter(src, dest)
source_markup = src.at_css(@source_selector)
destination_markup = dest.at_css(@destination_selector)

raise(Slimmer::SourceWrapperNotFoundError, "Source wrapper div not found", caller) if source_markup.nil? && wrapper_check?
if source_markup.nil? && wrapper_check?
raise(Slimmer::SourceWrapperNotFoundError, <<~END_STRING, caller)
Slimmer did not find the wrapper div in the source HTML.
The following cause can be safely ignored, other need
to be investigated. One possible cause is that the
requested format was different from HTML e.g. JavaScript,
but the action only supports the HTML template and layout.
Rails only applies layouts matching the requested format,
so the layout was not applied.
END_STRING
end

css_classes = []
css_classes << source_markup.attributes["class"].to_s.split(/ +/) if source_markup.has_attribute?("class")
Expand Down
7 changes: 0 additions & 7 deletions lib/slimmer/skin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ def process(processors, body, template, _rack_env)
end

def success(source_request, response, body)
original_body = body.dup
wrapper_id = options[:wrapper_id] || "wrapper"
template_wrapper_id = "wrapper" # All templates in Static use `#wrapper`

Expand All @@ -123,12 +122,6 @@ def success(source_request, response, body)

template_name = response.headers[Headers::TEMPLATE_HEADER] || "gem_layout"
process(processors, body, template(template_name), source_request.env)
rescue SourceWrapperNotFoundError => e
message = "#{e.message} "\
"at: #{source_request.base_url}#{source_request.path} "\
"length: #{original_body.to_s.length} "\
"body: #{original_body.to_s[0..2000]}"
raise SourceWrapperNotFoundError, message, caller
end
end
end

0 comments on commit d0d7d38

Please sign in to comment.