WebsockexNova.Gun.ConnectionWrapper.ErrorHandler (WebsockexNova v0.1.0)

View Source

Standardized error handling for the Gun ConnectionWrapper.

This module provides consistent error handling patterns for different types of errors encountered in the ConnectionWrapper. It ensures that:

  1. Errors are logged with appropriate context
  2. State is properly updated with error information
  3. Streams are cleaned up as needed
  4. Callbacks are notified with consistent error messages
  5. Proper return values are maintained

Summary

Functions

Handles async error response in handle_info callbacks.

Handles Gun-related connection errors.

Handles stream-related errors.

Handles transition errors when state machine transitions fail.

Handles wait_for_websocket_upgrade errors.

Functions

handle_async_error(stream_ref, reason, state)

@spec handle_async_error(
  reference() | nil,
  term(),
  WebsockexNova.Gun.ConnectionState.t()
) ::
  {:noreply, WebsockexNova.Gun.ConnectionState.t()}

Handles async error response in handle_info callbacks.

Parameters

  • stream_ref - Reference to the stream with the error (or nil)
  • reason - The error reason
  • state - Current connection state

Returns

{:noreply, updated_state} - For asynchronous contexts

handle_connection_error(reason, state)

@spec handle_connection_error(term(), WebsockexNova.Gun.ConnectionState.t()) ::
  {:reply, {:error, term()}, WebsockexNova.Gun.ConnectionState.t()}

Handles Gun-related connection errors.

Parameters

  • reason - The error reason
  • state - Current connection state

Returns

{:reply, {:error, reason}, state} - For synchronous contexts

handle_stream_error(stream_ref, reason, state)

@spec handle_stream_error(reference(), term(), WebsockexNova.Gun.ConnectionState.t()) ::
  {:reply, {:error, term()}, WebsockexNova.Gun.ConnectionState.t()}

Handles stream-related errors.

Parameters

  • stream_ref - Reference to the stream with the error
  • reason - The error reason
  • state - Current connection state

Returns

{:reply, {:error, reason}, state} - For synchronous contexts

handle_transition_error(current_state, target_state, reason, state)

@spec handle_transition_error(
  atom(),
  atom(),
  term(),
  WebsockexNova.Gun.ConnectionState.t()
) ::
  {:noreply, WebsockexNova.Gun.ConnectionState.t()}

Handles transition errors when state machine transitions fail.

Parameters

  • current_state - Current state name
  • target_state - Target state name
  • reason - The error reason
  • state - Current connection state

Returns

{:noreply, state} - For asynchronous contexts

handle_upgrade_error(stream_ref, reason, state)

@spec handle_upgrade_error(reference(), term(), WebsockexNova.Gun.ConnectionState.t()) ::
  {:reply, {:error, term()}, WebsockexNova.Gun.ConnectionState.t()}

Handles wait_for_websocket_upgrade errors.

Parameters

  • stream_ref - Reference to the stream with the error
  • reason - The error reason
  • state - Current connection state

Returns

{:reply, {:error, reason}, state} - For synchronous contexts