Skip to content

rpc middleware: return Self::Response instead of Result<Self::Response, Self::Error> #1547

Closed
@niklasad1

Description

@niklasad1

I guess the point of Error = Infallible here is that any "error" should be returned in the form of a MethodResponse to a client, and so it enforces that all errors are converted into proper JSON-RPC errors or whatever before they are emitted. Am I understanding that right?

(A bit like how in HTTP servers like Axum, any errors need to be converted to HTTP responses)

I geuss the reason to keep the Error associated type at all is just for internal middleware that might want to signal something went wrong, and then some other middleware that wraps it can take that error and decide what sort of response to turn it into? I think this makes sense, but I wonder if we have any examples that show this is useful? (Or maybe I am missing something more obvious!)

Originally posted by @jsdw in #1521 (comment)

TLDR; The question whether it is most ergonomic to have:

pub trait RpcServiceT {
	/// The error type.
	type Error: std::fmt::Debug;

	/// The response type
	type Response: ToJson;

	/// Processes a single JSON-RPC call, which may be a subscription or regular call.
	fn call<'a>(&self, request: Request<'a>) -> impl Future<Output = Result<Self::Response, Self::Error>> + Send + 'a;
}

or

pub trait RpcServiceT {
	/// The response type
	type Response: ToJson;

	/// Processes a single JSON-RPC call, which may be a subscription or regular call.
	fn call<'a>(&self, request: Request<'a>) -> impl Future<Output = Self::Response> + Send + 'a;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions