Module Good
enable you Early Return like error handling, by falling through.
import Good
User.changeset(%User{}, params)
|> Repo.insert
|> then(fn user ->
{:ok, "Hello, #{user.name}!"}
end)
|> otherwise(fn changeset ->
{:error, changeset.errors |> Enum.into(%{})}
end)
|> case do
# Everything comes here anyway
{:ok, message} -> json conn, message
{:error, reason} -> put_status(conn, 500) |> json reason
end
If available in Hex, the package can be installed as:
mix.exs
: def deps do
[{:good, "~> 0.0.1"}]
end
def application do
[applications: [:good]]
end