madshargreave
Action_fallback for channels?
Hi
I love the new action_fallback macro in my controllers. My controllers are now very clean and look something like this
def create(conn, params, identity, _claims) do
with {:ok, message} <- Messenger.send_message(identity, conn.assigns.conversation, params) do
conn
|> put_status(:created)
|> render(Shared.V1.MessageView, "show.json", current_identity: identity, message: message)
end
end
Now, I want to expose the same web API, but over websockets as well. I am thinking something like:
def handle_in("request", %{"method" => "messages.create", "data" => data, "context" => %{"id" => conversation_id}} = payload, socket) do
with {:ok, message} <- Messenger.send_message(socket.assigns.current_identity, conversation, data) do
payload = Shared.V1.MessageView.render("show.json", current_identity: socket.assigns.current_identity, message: message)
push socket, "response", payload
end
end
Ideally, similar to how it works with action_fallback in the controller, changeset errors would bubble up and be handled somewhere else.
Any suggestions on how best to accomplish this?
Most Liked
ibarch
Popular in Questions
Hi guys, i’m new in the Elixir world, and i have to say, that i love it!
i’m having some problem to understand anonymous functions with ...
New
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set?
Thanks.
New
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
Hello all!
I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors:
[WARN] - (starship::utils): Executing command ...
New
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
Hi!
Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New
Other popular topics
Hello, how can I check the Phoenix version ?
Thanks !
New
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
New
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
Hi All,
I set a environment variables in dev.exs , like below code.
when i start server, how can i set the ${enable} value?
thanks.
d...
New
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









