phtrivier
Handle phoenix socket.connect() error
I’m using phoenix 1.3.2
I have a socket that checks for user authentication at connection time:
def Socket do
use Phoenix.Socket
def connect(params, socket) do
case check_authentication_params(params) do
{:ok, authed_socket} -> {:ok, authed_socket}
_ -> :error
end
end
end
I connect in a browser with the phoenix npm package:
import { Socket } from 'phoenix';
let webSocket = new Socket(`....`);
webSocket.onError(error => {
// Handle error
});
webSocket.connect()
My problem is that, on the client side, in the webSocke.onError handler, the error event seems to be the same when:
- the connect succeeds, but later the connection is dropped (momentarily, for example, when my server restarts)
- the connection is done with wrong params, so the
connectfunction returns :error. I have log line that says:
WebSocket connection to '....t?vsn=2.0.0' failed: Error during WebSocket handshake: Unexpected response code: 403
But I cannot make the difference in the code.
What I want to do is to forcefully disconnect the websocket (to avoid repeated reconnection attempt) when I know the client does not have the proper credentials.
If I always use webSocket.disconnect in the error handler, then, as I understand it, I loose automatic reconnection in case of a network hicup.
Is there a way around that ?
Popular in Questions
Hey all,
I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
Hi everyone!
I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
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’m a new one to elixir
which editor can i use
vs code? or atom?
Thanks! :smiley:
New
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar.
I p...
New
Other popular topics
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
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum.
...
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 again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
New
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
Latest Phoenix Threads
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
- #forms
- #api
- #metaprogramming
- #hex
- #security









