Skip to content
This repository was archived by the owner on Jan 25, 2024. It is now read-only.

Commit 6c12d7f

Browse files
authored
Merge pull request #29 from wiktorkuchta/methodnotfound
Respond to unhandled methods with MethodNotFound
2 parents 4b6bce1 + 89f51c6 commit 6c12d7f

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/main.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,7 @@ impl App {
135135
let id = req.id.clone();
136136
match self.conn.handle_shutdown(&req) {
137137
Ok(true) => break,
138-
Ok(false) => {
139-
if let Err(err) = self.handle_request(req) {
140-
self.err(id, err);
141-
}
142-
}
138+
Ok(false) => self.handle_request(req),
143139
Err(err) => {
144140
// This only fails if a shutdown was
145141
// requested in the first place, so it
@@ -157,7 +153,7 @@ impl App {
157153
}
158154
}
159155
}
160-
fn handle_request(&mut self, req: Request) -> Result<(), Error> {
156+
fn handle_request(&mut self, req: Request) {
161157
fn cast<Kind>(req: &mut Option<Request>) -> Option<(RequestId, Kind::Params)>
162158
where
163159
Kind: RequestTrait,
@@ -214,8 +210,15 @@ impl App {
214210
}
215211
}
216212
self.reply(Response::new_ok(id, selections));
213+
} else {
214+
let req = req.expect("internal error: req should have been wrapped in Some");
215+
216+
self.reply(Response::new_err(
217+
req.id,
218+
ErrorCode::MethodNotFound as i32,
219+
format!("Unhandled method {}", req.method),
220+
))
217221
}
218-
Ok(())
219222
}
220223
fn handle_notification(&mut self, req: Notification) -> Result<(), Error> {
221224
match &*req.method {

0 commit comments

Comments
 (0)