67 {
68 ParamsType typed_params{};
69 try {
70 if (params.has_value()) {
71 typed_params = params.value().get<ParamsType>();
72 }
73 } catch (const nlohmann::json::exception& ex) {
74 throw std::runtime_error(
75 "Failed to parse parameters: " + std::string(ex.what()));
76 }
77
78 if constexpr (std::is_same_v<ErrorType, std::monostate>) {
79 if constexpr (std::is_void_v<ResultType>) {
80 co_await handler_(typed_params);
81 co_return nlohmann::json();
82 } else {
83 ResultType result = co_await handler_(typed_params);
84 co_return nlohmann::json(result);
85 }
86 } else {
87 auto result = co_await handler_(typed_params);
88 if (result) {
89 if constexpr (std::is_void_v<ResultType>) {
90 co_return nlohmann::json();
91 } else {
92 co_return nlohmann::json(*result);
93 }
94 } else {
95 throw result.error();
96 }
97 }
98 }