Snodo.Client.Transport behaviour (snodo v0.2.0)

Copy Markdown View Source

Behaviour for the connection underneath Snodo.Client.

A transport moves one complete JSON-RPC request to a server and returns the complete JSON-RPC response. Snodo.Client builds the request and decodes the response, so a transport never interprets result or error.

request/3 receives these options:

  • :timeout - milliseconds to wait for the response.
  • :dialect - the protocol dialect module that built the request. HTTP uses its transport_policy/1 to derive headers.

Failures of the connection itself are %Snodo.Error{kind: :transport}. Use connection_error/2 (-32000) and timeout_error/1 (-32001), the codes the official TypeScript SDK uses for the same client-side conditions.

Summary

Functions

The connection is closed, unreachable, or produced an unusable response.

No response arrived within timeout milliseconds.

Types

state()

@type state() :: term()

Callbacks

close(state)

@callback close(state()) :: :ok

connect(init_arg, opts)

@callback connect(init_arg :: term(), opts :: keyword()) ::
  {:ok, state()} | {:error, Snodo.Error.t()}

request(state, message, opts)

@callback request(state(), message :: map(), opts :: keyword()) ::
  {:ok, map()} | {:error, Snodo.Error.t()}

Functions

connection_error(message, cause)

@spec connection_error(String.t(), term()) :: Snodo.Error.t()

The connection is closed, unreachable, or produced an unusable response.

timeout_error(timeout)

@spec timeout_error(timeout()) :: Snodo.Error.t()

No response arrived within timeout milliseconds.