chore: add log

This commit is contained in:
appflowy
2022-08-15 22:40:54 +08:00
parent 2623974def
commit f841587c27
8 changed files with 39 additions and 15 deletions

View File

@ -14,7 +14,12 @@ where
fn into_bytes(self) -> Result<Bytes, DispatchError> {
match self.try_into() {
Ok(data) => Ok(data),
Err(e) => Err(InternalError::ProtobufError(format!("{:?}", e)).into()),
Err(e) => Err(InternalError::ProtobufError(format!(
"Serial {:?} to bytes failed:{:?}",
std::any::type_name::<T>(),
e
))
.into()),
}
}
}

View File

@ -55,7 +55,10 @@ where
{
fn respond_to(self, _request: &EventRequest) -> EventResponse {
match self.into_inner().into_bytes() {
Ok(bytes) => ResponseBuilder::Ok().data(bytes).build(),
Ok(bytes) => {
log::trace!("Serialize Data: {:?} to event response", std::any::type_name::<T>());
return ResponseBuilder::Ok().data(bytes).build();
}
Err(e) => e.into(),
}
}
@ -86,7 +89,11 @@ where
T: FromBytes,
{
match payload {
Payload::None => Err(InternalError::UnexpectedNone("Parse fail, expected payload".to_string()).into()),
Payload::None => Err(InternalError::UnexpectedNone(format!(
"Parse fail, expected payload:{:?}",
std::any::type_name::<T>()
))
.into()),
Payload::Bytes(bytes) => {
let data = T::parse_from_bytes(bytes.clone())?;
Ok(Data(data))

View File

@ -54,16 +54,18 @@ impl EventDispatcher {
callback: Some(Box::new(callback)),
};
let join_handle = dispatch.runtime.spawn(async move {
service
.call(service_ctx)
.await
.unwrap_or_else(|e| InternalError::Other(format!("{:?}", e)).as_response())
service.call(service_ctx).await.unwrap_or_else(|e| {
tracing::error!("Dispatch runtime error: {:?}", e);
InternalError::Other(format!("{:?}", e)).as_response()
})
});
DispatchFuture {
fut: Box::pin(async move {
join_handle.await.unwrap_or_else(|e| {
let error = InternalError::JoinError(format!("EVENT_DISPATCH join error: {:?}", e));
let msg = format!("EVENT_DISPATCH join error: {:?}", e);
tracing::error!("{}", msg);
let error = InternalError::JoinError(msg);
error.as_response()
})
}),