A normalized failure from a BRAVIA call.
Two very different things end up here. Sony returns application errors with an
HTTP 200 status and an "error" array in the body; those carry a :code. Anything
that fails below that — a timeout, a refused connection — has no code and arrives
via transport/2.
Match on :reason rather than :code; the codes are Sony's and the reasons are
stable across them.
The reason worth handling explicitly is :unauthorized. It means the TV rejected
the request because no valid Pre-Shared Key was sent. Enable one on the TV under
Settings → Network → Home Network → IP Control → Authentication by selecting
"Normal and Pre-Shared Key", then pass it as :psk to Bravia.new/2.
Summary
Functions
Maps a Sony error code to a reason atom, or :unknown.
Builds an error from a Sony [code, message] pair.
Builds an error for a failure below the application layer, such as a timeout.
Types
@type reason() :: :illegal_argument | :illegal_request | :illegal_state | :no_such_method | :unsupported_version | :unsupported_operation | :display_off | :unauthorized | :unknown | atom()
Functions
Maps a Sony error code to a reason atom, or :unknown.
iex> Bravia.Error.from_code(12)
:no_such_method
Builds an error from a Sony [code, message] pair.
Sony's message is frequently just the method name rather than prose, so it is carried through untouched but should not be shown to users on its own.
Builds an error for a failure below the application layer, such as a timeout.