Fix error recovery when serializing unknown structs in JS view payload

This commit is contained in:
Jonatan Kłosko 2022-08-04 00:28:32 +02:00
parent 732db0ed45
commit 6853bbd9a1

View file

@ -105,12 +105,15 @@ defmodule LivebookWeb.JSViewChannel do
defp run_safely(fun) do
try do
{:ok, fun.()}
catch
:error, %Protocol.UndefinedError{protocol: Jason.Encoder, value: value} ->
{:error, "value #{inspect(value)} is not JSON-serializable, use another data type"}
rescue
error ->
case error do
%Protocol.UndefinedError{protocol: Jason.Encoder, value: value} ->
{:error, "value #{inspect(value)} is not JSON-serializable, use another data type"}
:error, error ->
{:error, Exception.message(error)}
error ->
{:error, Exception.message(error)}
end
end
end