Skip to content

Instantly share code, notes, and snippets.

@nsomar
Created April 4, 2016 21:40
Show Gist options
  • Save nsomar/96f62ee12b0fe9769785c0c0a200d50b to your computer and use it in GitHub Desktop.
Save nsomar/96f62ee12b0fe9769785c0c0a200d50b 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