mirror of
https://github.com/woutdp/live_svelte
synced 2026-05-24 09:28:21 +00:00
Generalize SSR.NotConfigured exception
This commit is contained in:
parent
df7b4b8935
commit
1119f41cb2
4 changed files with 16 additions and 7 deletions
|
|
@ -81,7 +81,7 @@ defmodule LiveSvelte do
|
|||
|
||||
SSR.render(assigns.name, props, slots)
|
||||
rescue
|
||||
SSR.NodeNotConfigured -> nil
|
||||
SSR.NotConfigured -> nil
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue