diff --git a/app/controllers/liquid_embeds_controller.rb b/app/controllers/liquid_embeds_controller.rb
index 69c21efde..11759e5e3 100644
--- a/app/controllers/liquid_embeds_controller.rb
+++ b/app/controllers/liquid_embeds_controller.rb
@@ -5,6 +5,17 @@ class LiquidEmbedsController < ApplicationController
def show
set_surrogate_key_header params.to_s
+
+ begin
+ @rendered_node = Liquid::Template
+ .parse("{% #{params[:embeddable]} #{params[:args]} %}")
+ .root
+ .nodelist
+ .first
+ .render({})
+ rescue StandardError
+ raise ActionController::RoutingError, "Not Found"
+ end
end
private
diff --git a/app/views/liquid_embeds/show.html.erb b/app/views/liquid_embeds/show.html.erb
index c0c1396bc..bb4f6ee1d 100644
--- a/app/views/liquid_embeds/show.html.erb
+++ b/app/views/liquid_embeds/show.html.erb
@@ -2,11 +2,7 @@
<% cache "liquid_tag_styles_#{ForemInstance.deployed_at}", expires_in: 8.hours do #TODO: Render specific ltag class instead of everything %>
<% end %>
-<% begin %>
- <% @liquid_node = Liquid::Template.parse("{% #{params[:embeddable]} #{params[:args]} %}").root.nodelist.first %>
- <%= @liquid_node.render({}) %>
-<% rescue %>
- <% raise ActionController::RoutingError, "Not Found" %>
-<% end %>
+
+<%= @rendered_node %>
diff --git a/spec/requests/liquid_embeds_spec.rb b/spec/requests/liquid_embeds_spec.rb
index 88c7f140f..f9834e36b 100644
--- a/spec/requests/liquid_embeds_spec.rb
+++ b/spec/requests/liquid_embeds_spec.rb
@@ -17,7 +17,7 @@ RSpec.describe "LiquidEmbeds", type: :request, vcr: { cassette_name: "twitter_cl
it "renders 404 if improper tweet" do
expect do
get liquid_embed_path("tweet", args: "improper")
- end.to raise_error(ActionView::Template::Error)
+ end.to raise_error(ActionController::RoutingError)
end
it "contains base target parent" do