retort v2.7.0 Retort.Response View Source
A JSON-RPC Response object
Link to this section Summary
Functions
Generates error response with the given message and corresponding code
Converts JSON decoded map with String.t
keys to t
Decodes a JSON-encoded string back to a t
Link to this section Types
t() :: %Retort.Response{error: Retort.Response.Error.t() | nil, id: integer() | String.t() | nil, jsonrpc: String.t(), result: String.t() | false | true | integer() | float() | [...] | %{} | nil}
Link to this section Functions
Generates error response with the given message and corresponding code
error(t(), Ecto.Changeset.t() | Alembic.Document.t() | String.t()) :: t()
from_json(%{required(binary()) => any()}) :: t() | no_return()
Converts JSON decoded map with String.t
keys to t
.
Decodes a JSON-encoded string back to a t
.
Decode a successful response
iex> Retort.Response.from_string(~S|{“id”: 1, “jsonrpc”: “2.0”, “result”: true}|) %Retort.Response{error: nil, id: 1, jsonrpc: “2.0”, result: true}
Decode an error response with data
iex> Retort.Response.from_string( …> ~S|{“error”: {“code”: -32602, “data”: [“foo”], “message”: “Invalid params”}, “id”: 2, “jsonrpc”: “2.0”}| …> ) %Retort.Response{
error: %Retort.Response.Error{code: -32602, data: ["foo"], message: "Invalid params"},
id: 2,
jsonrpc: "2.0",
result: nil
}
Decode an error response without data
iex> Retort.Response.from_string( …> ~S|{“error”: {“code”: -32600, “message”: “Invalid Request”}, “id”: 3, “jsonrpc”: “2.0”}| …> ) %Retort.Response{
error: %Retort.Response.Error{code: -32600, message: "Invalid Request"},
id: 3,
jsonrpc: "2.0",
result: nil
}