fix: send error back (#556)
This commit is contained in:
parent
bd3a704200
commit
6bf45a0b5d
|
@ -82,6 +82,16 @@ impl<R> ResponseData<R> {
|
|||
}
|
||||
}
|
||||
|
||||
impl ResponseData<serde_json::Value> {
|
||||
/// Encode the error to json value if it is an error
|
||||
pub fn into_value(self) -> serde_json::Result<serde_json::Value> {
|
||||
match self {
|
||||
ResponseData::Success { result } => Ok(result),
|
||||
ResponseData::Error { error } => serde_json::to_value(error),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
|
@ -181,7 +181,7 @@ where
|
|||
},
|
||||
// Handle socket messages
|
||||
msg = self.socket_reader.next() => match msg {
|
||||
Some(Ok(msg)) => self.handle_socket(read_buffer, msg).await?,
|
||||
Some(Ok(msg)) => self.handle_socket(read_buffer, msg)?,
|
||||
Some(Err(err)) => {
|
||||
error!("IPC read error: {:?}", err);
|
||||
return Err(err.into());
|
||||
|
@ -207,7 +207,7 @@ where
|
|||
}
|
||||
|
||||
if let Err(err) = self.socket_writer.write(request.as_bytes()).await {
|
||||
error!("WS connection error: {:?}", err);
|
||||
error!("IPC connection error: {:?}", err);
|
||||
self.pending.remove(&id);
|
||||
}
|
||||
}
|
||||
|
@ -229,7 +229,7 @@ where
|
|||
Ok(())
|
||||
}
|
||||
|
||||
async fn handle_socket(
|
||||
fn handle_socket(
|
||||
&mut self,
|
||||
read_buffer: &mut Vec<u8>,
|
||||
bytes: bytes::Bytes,
|
||||
|
@ -292,7 +292,7 @@ where
|
|||
let id = output.id;
|
||||
|
||||
// Converts output into result, to send data if valid response.
|
||||
let value = output.data.into_result()?;
|
||||
let value = output.data.into_value()?;
|
||||
|
||||
let response_tx = self.pending.remove(&id).ok_or_else(|| {
|
||||
IpcError::ChannelError("No response channel exists for the response ID".to_string())
|
||||
|
|
Loading…
Reference in New Issue