| 593 | } |
| 594 | |
| 595 | async fn dispatch_custom_request( |
| 596 | &self, |
| 597 | _id: serde_json::Value, |
| 598 | request: serde_json::Value, |
| 599 | plugin: &Plugin<S>, |
| 600 | ) -> Result<serde_json::Value, Error> { |
| 601 | let method = request |
| 602 | .get("method") |
| 603 | .context("Missing 'method' in request")? |
| 604 | .as_str() |
| 605 | .context("'method' is not a string")?; |
| 606 | |
| 607 | let params = request |
| 608 | .get("params") |
| 609 | .context("Missing 'params' field in request")?; |
| 610 | let callback = self |
| 611 | .rpcmethods |
| 612 | .get(method) |
| 613 | .with_context(|| anyhow!("No handler for method '{}' registered", method))?; |
| 614 | |
| 615 | trace!( |
| 616 | "Dispatching custom request: method={}, params={}", |
| 617 | method, |
| 618 | params |
| 619 | ); |
| 620 | callback(plugin.clone(), params.clone()).await |
| 621 | } |
| 622 | |
| 623 | async fn dispatch_custom_notification( |
| 624 | &self, |