Skip to content

Commit

Permalink
Classify GRPC transport errors as operational (#29083)
Browse files Browse the repository at this point in the history
Apply same logic to searchlight/funun clients as well as backend callbacks

GitOrigin-RevId: dbe8dacd702cbb1dcd921c939d9eccd7d5f85737
  • Loading branch information
nipunn1313 authored and Convex, Inc. committed Aug 21, 2024
1 parent d25cba2 commit cc5b46b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions crates/common/src/grpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ use std::{
};

use futures::Future;
use pb::error_metadata::ErrorMetadataStatusExt;
use sentry::integrations::tower as sentry_tower;
use tonic::{
server::NamedService,
service::Routes,
Response,
Status,
};
use tonic_health::{
server::{
Expand Down Expand Up @@ -81,3 +84,10 @@ impl ConvexGrpcService {
Ok(())
}
}

pub fn handle_response<T>(response: Result<Response<T>, Status>) -> anyhow::Result<T> {
match response {
Ok(response) => Ok(response.into_inner()),
Err(status) => Err(status.into_anyhow()),
}
}
2 changes: 2 additions & 0 deletions crates/pb/src/error_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ impl ErrorMetadataStatusExt for tonic::Status {
Err(err) => return err.context("Failed to parse ErrorMetadata proto"),
};
error = error.context(error_metadata)
} else if error.is::<tonic::transport::Error>() {
error = error.context(ErrorMetadata::operational_internal_server_error());
}
error
}
Expand Down

0 comments on commit cc5b46b

Please sign in to comment.