| 621 | } |
| 622 | |
| 623 | async fn dispatch_custom_notification( |
| 624 | &self, |
| 625 | notification: serde_json::Value, |
| 626 | plugin: &Plugin<S>, |
| 627 | ) -> Result<(), Error> |
| 628 | where |
| 629 | S: Send + Clone, |
| 630 | { |
| 631 | trace!("Dispatching custom notification {:?}", notification); |
| 632 | let method = notification |
| 633 | .get("method") |
| 634 | .context("Missing 'method' in notification")? |
| 635 | .as_str() |
| 636 | .context("'method' is not a string")?; |
| 637 | let params = notification |
| 638 | .get("params") |
| 639 | .context("Missing 'params' field in notification")?; |
| 640 | let callback = self |
| 641 | .subscriptions |
| 642 | .get(method) |
| 643 | .with_context(|| anyhow!("No handler for method '{}' registered", method))?; |
| 644 | trace!( |
| 645 | "Dispatching custom request: method={}, params={}", |
| 646 | method, |
| 647 | params |
| 648 | ); |
| 649 | if let Err(e) = callback(plugin.clone(), params.clone()).await { |
| 650 | log::error!("Error in notification handler '{}': {}", method, e); |
| 651 | } |
| 652 | Ok(()) |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | impl<S> Plugin<S> |