You might use
socket.onError(() => console.log("there was an error with the connection!"))
socket.onClose(() => console.log("the connection dropped"))
channel.onError(() => console.log("there was an error!"))
channel.onClose(() => console.log("the channel has gone away gracefully"))
See https://github.com/phoenixframework/phoenix/blob/master/assets/js/phoenix.js#L68-L95 for more info about different socket and channel hooks.