From 1119f41cb2cb3b8c7401b43cd928ab587fb07b72 Mon Sep 17 00:00:00 2001 From: Douglas Vought Date: Thu, 14 Sep 2023 18:31:55 -0400 Subject: [PATCH] Generalize SSR.NotConfigured exception --- lib/component.ex | 2 +- lib/ssr.ex | 7 ++----- lib/ssr/node_js.ex | 7 ++++++- test/ssr_test.exs | 7 +++++++ 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/component.ex b/lib/component.ex index 01c96b5..93f3cf1 100644 --- a/lib/component.ex +++ b/lib/component.ex @@ -81,7 +81,7 @@ defmodule LiveSvelte do SSR.render(assigns.name, props, slots) rescue - SSR.NodeNotConfigured -> nil + SSR.NotConfigured -> nil end end diff --git a/lib/ssr.ex b/lib/ssr.ex index e650651..7949e98 100644 --- a/lib/ssr.ex +++ b/lib/ssr.ex @@ -1,10 +1,7 @@ -defmodule LiveSvelte.SSR.NodeNotConfigured do +defmodule LiveSvelte.SSR.NotConfigured do @moduledoc false - defexception message: """ - NodeJS is not configured. Please add the following to your application.ex: - {NodeJS.Supervisor, [path: LiveSvelte.SSR.server_path(), pool_size: 4]}, - """ + defexception [:message] end defmodule LiveSvelte.SSR do diff --git a/lib/ssr/node_js.ex b/lib/ssr/node_js.ex index 634c518..6c0bc6a 100644 --- a/lib/ssr/node_js.ex +++ b/lib/ssr/node_js.ex @@ -6,7 +6,12 @@ defmodule LiveSvelte.SSR.NodeJS do try do NodeJS.call!({"server", "render"}, [name, props, slots]) catch - :exit, {:noproc, _} -> raise LiveSvelte.SSR.NodeNotConfigured + :exit, {:noproc, _} -> + message = """ + NodeJS is not configured. Please add the following to your application.ex: + {NodeJS.Supervisor, [path: LiveSvelte.SSR.NodeJS.server_path(), pool_size: 4]}, + """ + raise %LiveSvelte.SSR.NotConfigured{message: message} end end diff --git a/test/ssr_test.exs b/test/ssr_test.exs index 67d004f..d1c633d 100644 --- a/test/ssr_test.exs +++ b/test/ssr_test.exs @@ -6,6 +6,13 @@ defmodule LiveSvelte.SSRTest do assert Application.get_env(:live_svelte, :ssr_module) == LiveSvelte.SSR.NodeJS end + test "Node.js raises the correct exception" do + load_config("config/config.exs") + assert_raise(LiveSvelte.SSR.NotConfigured, fn -> + LiveSvelte.SSR.NodeJS.render("Test", %{}, %{}) + end) + end + test "It uses a different SSR module" do load_config("test/ssr_test/test_config.exs") assert Application.get_env(:live_svelte, :ssr_module) == SomeOtherSSRModule