WebsockexAdapter.Examples.Docs.ErrorHandling (WebsockexAdapter v0.1.1)

View Source

Error handling and retry patterns from Examples.md

Summary

Functions

Returns a specification to start this module under a supervisor.

Returns the current state of the error handler.

Sends a message through the WebSocket connection.

Starts a GenServer that manages a WebSocket connection with automatic retry.

Types

state()

@type state() :: %{
  client: pid() | nil,
  url: String.t(),
  opts: keyword(),
  retry_count: non_neg_integer()
}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_state()

@spec get_state() :: state()

Returns the current state of the error handler.

Returns

The internal state map including connection status and retry count.

send_message(message)

@spec send_message(term()) :: :ok | {:error, :not_connected}

Sends a message through the WebSocket connection.

Parameters

  • message - Message to send (will be JSON encoded)

Returns

  • :ok on success
  • {:error, :not_connected} if not connected

start_link(url, opts \\ [])

@spec start_link(
  String.t(),
  keyword()
) :: GenServer.on_start()

Starts a GenServer that manages a WebSocket connection with automatic retry.

Parameters

  • url - WebSocket URL to connect to
  • opts - Connection options

Returns

{:ok, pid} on success or {:error, reason} on failure.