Make NotFoundError reusable

This commit is contained in:
José Valim 2023-07-13 14:09:13 +02:00
parent 92fa990620
commit 670f099e5e
2 changed files with 4 additions and 7 deletions

View file

@ -1,4 +1,6 @@
defmodule Livebook.Secrets do
# This module is used to store secrets on Livebook.Storage for specific hubs.
# Currently it is only used by personal hub.
@moduledoc false
alias Livebook.Hubs.Provider

View file

@ -7,12 +7,7 @@ defmodule LivebookWeb.Hub.Edit.PersonalComponent do
defmodule NotFoundError do
@moduledoc false
defexception [:secret, plug_status: 404]
def message(%{secret: secret}) do
"could not find secret matching \"#{secret}\""
end
defexception [:message, plug_status: 404]
end
@impl true
@ -25,7 +20,7 @@ defmodule LivebookWeb.Hub.Edit.PersonalComponent do
secret_value =
if assigns.live_action == :edit_secret do
Enum.find_value(secrets, &(&1.name == secret_name and &1.value)) ||
raise(NotFoundError, secret: secret_name)
raise(NotFoundError, "could not find secret matching #{inspect(secret_name)}")
end
{:ok,