Simple error handling for WebSocket connections.
Handles common error scenarios:
- Connection errors (network failures)
- Protocol errors (malformed frames)
- Authentication errors
- Timeout errors
Passes raw errors without wrapping to preserve original error information.
Provides human-readable explanations via explain/1.
API Functions
| Function | Arity | Description | Param Kinds |
|---|---|---|---|
explain | 1 | Get a human-readable explanation with fix suggestions for an error. | error: value |
handle_error | 1 | Return the appropriate action for an error. | error: value |
recoverable? | 1 | Check if an error is recoverable through reconnection. | error: value |
categorize_error | 1 | Categorize an error as recoverable or fatal. | error: value |
Summary
Types
Human-readable error explanation with fix suggestions.
Functions
Categorizes errors into recoverable vs non-recoverable types.
Returns a human-readable explanation for an error.
Handles errors by returning appropriate actions.
Determines if an error is recoverable through reconnection.
Types
Functions
Categorizes errors into recoverable vs non-recoverable types.
Tags the error as {:recoverable, error} (network/transient) or
{:fatal, error} (protocol/auth) based on pattern matching.
@spec explain(term()) :: explanation()
Returns a human-readable explanation for an error.
Provides a clear message describing what happened, a suggestion for how to fix it, and optionally a documentation URL for more information.
Examples
iex> ZenWebsocket.ErrorHandler.explain({:error, :econnrefused})
%{
message: "Connection refused by server",
suggestion: "Check that the server is running and verify the URL is correct",
docs_url: nil
}
iex> ZenWebsocket.ErrorHandler.explain({:error, :unauthorized})
%{
message: "Authentication failed",
suggestion: "Check your API credentials are valid and not expired",
docs_url: nil
}
@spec handle_error(term()) :: :reconnect | :stop
Handles errors by returning appropriate actions.
Returns either :reconnect or :stop based on error recoverability.
Determines if an error is recoverable through reconnection.