Skip to content

Instantly share code, notes, and snippets.

@marciol
Forked from nsomar/with.exs
Created April 15, 2016 14:25
Show Gist options
  • Save marciol/ea37747aaf681d88b3e9fd11f5c05217 to your computer and use it in GitHub Desktop.
Save marciol/ea37747aaf681d88b3e9fd11f5c05217 to your computer and use it in GitHub Desktop.
Handling errors with `with`
res =
with {:ok} <- validate_request(request),
{:ok, user} <- get_user(request),
{:ok} <- update_db(user),
{:ok} <- send_email(user) do
return_http_message
end
case res do
{:error, x} -> IO.inspect("Error: " <> x)
_ -> {:ok} #Success
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment