Packages
phoenix_ecto
4.3.0
4.7.0
4.6.6
4.6.5
4.6.4
4.6.3
4.6.2
4.6.1
4.6.0
4.5.1
4.5.0
4.4.3
4.4.2
4.4.1
4.4.0
4.3.0
4.2.1
4.2.0
4.1.0
4.0.0
3.6.0
3.5.0
retired
3.4.0
3.3.0
3.2.3
3.2.2
3.2.1
3.2.0
3.1.0
3.1.0-rc.0
3.0.1
3.0.0
3.0.0-rc.0
3.0.0-beta.2
3.0.0-beta.1
3.0.0-beta.0
2.0.3
2.0.2
2.0.1
2.0.0
1.2.0
1.1.0
1.0.0
0.9.0
0.8.1
0.8.0
0.7.0
0.6.0
0.5.0
0.4.0
0.3.2
0.3.1
0.3.0
0.2.0
0.1.0
Integration between Phoenix & Ecto
Current section
Files
Jump to
Current section
Files
lib/phoenix_ecto/plug.ex
errors = [
{Ecto.CastError, 400},
{Ecto.Query.CastError, 400},
{Ecto.NoResultsError, 404},
{Ecto.StaleEntryError, 409}
]
excluded_exceptions = Application.get_env(:phoenix_ecto, :exclude_ecto_exceptions_from_plug, [])
for {exception, status_code} <- errors do
unless exception in excluded_exceptions do
defimpl Plug.Exception, for: exception do
def status(_), do: unquote(status_code)
def actions(_), do: []
end
end
end
unless Ecto.SubQueryError in excluded_exceptions do
defimpl Plug.Exception, for: Ecto.SubQueryError do
def status(sub_query_error) do
Plug.Exception.status(sub_query_error.exception)
end
def actions(_), do: []
end
end
unless Phoenix.Ecto.PendingMigrationError in excluded_exceptions do
defimpl Plug.Exception, for: Phoenix.Ecto.PendingMigrationError do
def status(_error), do: 503
def actions(%{repo: repo}),
do: [
%{
label: "Run migrations for repo",
handler: {__MODULE__, :migrate, [repo]}
}
]
def migrate(repo), do: Ecto.Migrator.run(repo, :up, all: true)
end
end
unless Phoenix.Ecto.StorageNotCreatedError in excluded_exceptions do
defimpl Plug.Exception, for: Phoenix.Ecto.StorageNotCreatedError do
def status(_error), do: 503
def actions(%{repo: repo}),
do: [
%{
label: "Create database for repo",
handler: {__MODULE__, :storage_up, [repo]}
}
]
def storage_up(repo), do: repo.__adapter__().storage_up(repo.config())
end
end