feat: handle JsonRpcMessage::Error messages to propagate to the user
This commit is contained in:
parent
08b73f3001
commit
22b11ea127
2 changed files with 26 additions and 8 deletions
|
|
@ -111,13 +111,23 @@ impl SseActor {
|
||||||
// Attempt to parse the SSE data as a JsonRpcMessage
|
// Attempt to parse the SSE data as a JsonRpcMessage
|
||||||
match serde_json::from_str::<JsonRpcMessage>(&e.data) {
|
match serde_json::from_str::<JsonRpcMessage>(&e.data) {
|
||||||
Ok(message) => {
|
Ok(message) => {
|
||||||
// If it's a response, complete the pending request
|
match &message {
|
||||||
if let JsonRpcMessage::Response(resp) = &message {
|
JsonRpcMessage::Response(response) => {
|
||||||
if let Some(id) = &resp.id {
|
if let Some(id) = &response.id {
|
||||||
pending_requests.respond(&id.to_string(), Ok(message)).await;
|
pending_requests
|
||||||
|
.respond(&id.to_string(), Ok(message))
|
||||||
|
.await;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
JsonRpcMessage::Error(error) => {
|
||||||
|
if let Some(id) = &error.id {
|
||||||
|
pending_requests
|
||||||
|
.respond(&id.to_string(), Ok(message))
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {} // TODO: Handle other variants (Request, etc.)
|
||||||
}
|
}
|
||||||
// If it's something else (notification, etc.), handle as needed
|
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
warn!("Failed to parse SSE message: {err}");
|
warn!("Failed to parse SSE message: {err}");
|
||||||
|
|
|
||||||
|
|
@ -87,10 +87,18 @@ impl StdioActor {
|
||||||
"Received incoming message"
|
"Received incoming message"
|
||||||
);
|
);
|
||||||
|
|
||||||
if let JsonRpcMessage::Response(response) = &message {
|
match &message {
|
||||||
if let Some(id) = &response.id {
|
JsonRpcMessage::Response(response) => {
|
||||||
pending_requests.respond(&id.to_string(), Ok(message)).await;
|
if let Some(id) = &response.id {
|
||||||
|
pending_requests.respond(&id.to_string(), Ok(message)).await;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
JsonRpcMessage::Error(error) => {
|
||||||
|
if let Some(id) = &error.id {
|
||||||
|
pending_requests.respond(&id.to_string(), Ok(message)).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {} // TODO: Handle other variants (Request, etc.)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
line.clear();
|
line.clear();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue