Skip to content

Instantly share code, notes, and snippets.

@nwalker
Forked from lyo5ha/Which one is better?
Last active February 11, 2019 13:11
Show Gist options
  • Save nwalker/a227a6a83bb1d1612576f6bfaf6aa391 to your computer and use it in GitHub Desktop.
Save nwalker/a227a6a83bb1d1612576f6bfaf6aa391 to your computer and use it in GitHub Desktop.
def show(conn, _params) do
invoice_id = get_session(conn, :invoice_id)
invoice_access_token = get_session(conn, :access_token)
cond
is_nil(invoice_id) or is_nil(invoice_access_token) -> render_error(conn, _params)
_ -> render_form(conn, invoice_id, invoice_access_token)
end
end
def w_nil(nil, k), do: {:error, {k, :nil}}
def w_nil(v, k), do: {v, k}
def show(conn, _params) do
with {:invoice_id, iid} <- get_session(conn, :invoice_id) |> w_nil(:invoice_id),
{:invoice_access_token, iat} <- get_session(conn, :access_token) |> w_nil(:invoice_access_token)
do
render_form(conn, iid, iat)
else
_ -> render_error(conn, _params)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment