Typed error codes and structured error data #4
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
The JSON-RPC layer currently uses bare integer literals for error codes, making it hard for consumers to distinguish error types without magic numbers. The
datafield in error responses is also untyped (Option<String>), preventing structured metadata from being attached.Goals
error_codesmodule with named constants for all standard JSON-RPC 2.0 codes plus theAPPLICATION_ERROR(-32000) application codeJsonRpcError.datafromOption<String>toOption<Value>to carry structured error metadatais_application_error()andis_method_not_found()helpers for ergonomic server-side dispatcherror_codesconstants in the client crate so consumers can distinguish errors without magic-number comparisonsdata: Option<Value>to the internal client-sideRpcErrordeserialization struct to prevent data loss