JSONRPC2Plug.Error (jsonrpc2_plug v0.1.0)

Link to this section Summary

Functions

Create error struct with predefined errors.

Create error struct.

Create error struct with custom errors.

Link to this section Types

Specs

code() :: integer()

Specs

data() :: String.t() | map() | keyword()

Specs

error() :: %{:code => code(), :message => message(), optional(:data) => data()}

Specs

id() :: String.t() | number() | nil

Specs

message() :: String.t()

Specs

raw_code() :: integer() | atom()

Specs

t() :: %JSONRPC2Plug.Error{error: error(), id: id(), jsonrpc: String.t()}

Link to this section Functions

Link to this function

code2error(code)

Specs

code2error(atom()) :: {code(), message()}

Specs

new(id(), atom()) :: t()

Create error struct with predefined errors.

Example:

iex> Error.new("123", :invalid_request)
%Error{id: "123", error: %{code: -32600, message: "Invalid request"}, jsonrpc: "2.0"}
Link to this function

new(id, code, message_or_data)

Specs

new(id(), raw_code(), message() | data()) :: t()

Create error struct.

Example:

iex> Error.new("123", :invalid_params, %{"x" => ["is not a integer"]})
%Error{id: "123", error: %{code: -32602, message: "Invalid params", data: %{"x" => ["is not a integer"]}}, jsonrpc: "2.0"}

iex> Error.new("123", 500, "Some valuable error")
%Error{id: "123", error: %{code: 500, message: "Some valuable error"}, jsonrpc: "2.0"}
Link to this function

new(id, code, message, data)

Specs

new(id(), raw_code(), message(), data()) :: t()

Create error struct with custom errors.

Example:

iex> Error.new("123", 500, "Some valuable error", "details")
%Error{id: "123", error: %{code: 500, message: "Some valuable error", data: "details"}, jsonrpc: "2.0"}