Open ralphjzhang opened 6 months ago
I realize that adding some helper:
template <typename Result>
struct expected_helper
{
static constexpr bool is_expecting_rpc_error = false;
using expected_t = std::expected<Result, rpc::error>;
};
template <typename Expected>
struct expected_helper<expected<Expected, rpc::error>>
{
static constexpr bool is_expecting_rpc_error = true;
using expected_t = std::expected<Expected, rpc::error>;
};
and use it to extract those methods returning expected<T, rpc::error> would do the job, would that PR get accepted?
Ah, that was an unintended consequence of adding general support for std::expected
. This should definitely be fixed. I'll experiment with a solution before I ask for a PR. Thanks for bringing this up.
After thinking about this some more, I have some questions. Are you trying to replace rpc::error
with your own error class?
So far I find using rpc error is fine for me, but from design point of view, maybe it's a good idea to allow using, e.g, derived class of rpc error or some sort ...
Try to return custom errors from json-rpc server methods like
but the response actually use the returned error as the result payload, i.e. the result look like
instead of using the error as json-rpc error, like
Is that possible to integrate error handling with the method handler?