Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
chore better team customer errors (#4702)
Will Hutchinson2381038660cf
diff --git a/rust/cloud-storage/teams/src/domain/model.rs b/rust/cloud-storage/teams/src/domain/model.rsindex 1bc7a34589..2f5fe35b76 100644--- a/rust/cloud-storage/teams/src/domain/model.rs+++ b/rust/cloud-storage/teams/src/domain/model.rs@@ -425,7 +425,7 @@ pub enum RemoveUserFromTeamError {#[error("There is no subscription for the team")]NoSubscription,/// Underlying customer error- #[error("Underlying customer error")]+ #[error("Underlying customer error {0}")]CustomerError(#[from] CustomerError),/// The user is the owner of the team#[error("Cannot remove owner")]@@ -499,7 +499,7 @@ pub enum DeleteTeamError {#[error("Underlying team error")]TeamError(#[from] TeamError),/// Underlying customer error- #[error("Underlying customer error")]+ #[error("Underlying customer error {0}")]CustomerError(#[from] CustomerError),/// Remove roles from user error#[error("Remove roles from user error")]@@ -516,7 +516,7 @@ pub enum JoinTeamError {#[error("Underlying team error")]TeamError(#[from] TeamError),/// Underlying customer error- #[error("Underlying customer error")]+ #[error("Underlying customer error {0}")]CustomerError(#[from] CustomerError),/// The user was not invited to the team#[error("User not invited")]@@ -567,3 +567,6 @@ pub enum TeamCheckoutError {#[error("User already has an active subscription")]AlreadySubscribed,}++#[cfg(test)]+mod test;diff --git a/rust/cloud-storage/teams/src/domain/model/test.rs b/rust/cloud-storage/teams/src/domain/model/test.rsnew file mode 100644index 0000000000..dcd0560071--- /dev/null+++ b/rust/cloud-storage/teams/src/domain/model/test.rs@@ -0,0 +1,51 @@+use super::*;++const CUSTOMER_STORAGE_ERROR: &str = "sentinel customer storage error";++fn customer_storage_error() -> CustomerError {+ CustomerError::StorageLayerError(anyhow::anyhow!(CUSTOMER_STORAGE_ERROR))+}++fn assert_preserves_customer_storage_error(error: impl std::fmt::Display) {+ let message = error.to_string();+ assert!(+ message.contains(CUSTOMER_STORAGE_ERROR),+ "customer storage error was missing from: {message}"+ );+}++#[test]+fn invite_users_to_team_error_preserves_customer_storage_error() {+ let error = InviteUsersToTeamError::from(customer_storage_error());+ assert_preserves_customer_storage_error(error);+}++#[test]+fn remove_user_from_team_error_preserves_customer_storage_error() {+ let error = RemoveUserFromTeamError::from(customer_storage_error());+ assert_preserves_customer_storage_error(error);+}++#[test]+fn remove_team_invite_error_preserves_customer_storage_error() {+ let error = RemoveTeamInviteError::from(customer_storage_error());+ assert_preserves_customer_storage_error(error);+}++#[test]+fn delete_team_error_preserves_customer_storage_error() {+ let error = DeleteTeamError::from(customer_storage_error());+ assert_preserves_customer_storage_error(error);+}++#[test]+fn join_team_error_preserves_customer_storage_error() {+ let error = JoinTeamError::from(customer_storage_error());+ assert_preserves_customer_storage_error(error);+}++#[test]+fn team_checkout_error_preserves_customer_storage_error() {+ let error = TeamCheckoutError::from(customer_storage_error());+ assert_preserves_customer_storage_error(error);+}diff --git a/rust/cloud-storage/teams/src/inbound/axum_router/invite_to_team.rs b/rust/cloud-storage/teams/src/inbound/axum_router/invite_to_team.rsindex b03bf29431..fbe38c5d82 100644--- a/rust/cloud-storage/teams/src/inbound/axum_router/invite_to_team.rs+++ b/rust/cloud-storage/teams/src/inbound/axum_router/invite_to_team.rs@@ -28,7 +28,7 @@ pub struct InviteToTeamRequest {#[derive(Debug, thiserror::Error)]pub enum InviteToTeamError {/// Unable to invite users to team- #[error("unable to invite users to team")]+ #[error("unable to invite users to team: {0}")]InviteUsersToTeamError(#[from] InviteUsersToTeamError),/// Invalid emails detected#[error("unable to parse email")]@@ -60,6 +60,12 @@ impl axum::response::IntoResponse for InviteToTeamError {message: "too many emails".into(),}),),+ InviteUsersToTeamError::CustomerError(_) => (+ StatusCode::INTERNAL_SERVER_ERROR,+ Json(ErrorResponse {+ message: "internal server error".into(),+ }),+ ),_ => (StatusCode::INTERNAL_SERVER_ERROR,Json(ErrorResponse {diff --git a/rust/cloud-storage/teams/src/inbound/axum_router/mod.rs b/rust/cloud-storage/teams/src/inbound/axum_router/mod.rsindex ef77a7f709..9b7626c4a5 100644--- a/rust/cloud-storage/teams/src/inbound/axum_router/mod.rs+++ b/rust/cloud-storage/teams/src/inbound/axum_router/mod.rs@@ -188,7 +188,7 @@ impl IntoResponse for DeleteTeamError {DeleteTeamError::CustomerError(_) => (StatusCode::INTERNAL_SERVER_ERROR,Json(ErrorResponse {- message: "unable to delete team subscription".into(),+ message: "internal server error".into(),}),),}@@ -205,6 +205,12 @@ impl IntoResponse for InviteUsersToTeamError {message: "too many emails".into(),}),),+ InviteUsersToTeamError::CustomerError(_) => (+ StatusCode::INTERNAL_SERVER_ERROR,+ Json(ErrorResponse {+ message: "internal server error".into(),+ }),+ ),_ => (StatusCode::INTERNAL_SERVER_ERROR,Json(ErrorResponse {@@ -218,13 +224,21 @@ impl IntoResponse for InviteUsersToTeamError {impl IntoResponse for JoinTeamError {fn into_response(self) -> Response {- (- StatusCode::INTERNAL_SERVER_ERROR,- Json(ErrorResponse {- message: "unable to join team".into(),- }),- )- .into_response()+ match self {+ JoinTeamError::CustomerError(_) => (+ StatusCode::INTERNAL_SERVER_ERROR,+ Json(ErrorResponse {+ message: "internal server error".into(),+ }),+ ),+ _ => (+ StatusCode::INTERNAL_SERVER_ERROR,+ Json(ErrorResponse {+ message: "unable to join team".into(),+ }),+ ),+ }+ .into_response()}}@@ -243,6 +257,12 @@ impl IntoResponse for RemoveTeamInviteError {message: "user not in team".into(),}),),+ RemoveTeamInviteError::CustomerError(_) => (+ StatusCode::INTERNAL_SERVER_ERROR,+ Json(ErrorResponse {+ message: "internal server error".into(),+ }),+ ),_ => (StatusCode::INTERNAL_SERVER_ERROR,Json(ErrorResponse {@@ -275,6 +295,12 @@ impl IntoResponse for RemoveUserFromTeamError {message: "user not in team".into(),}),),+ RemoveUserFromTeamError::CustomerError(_) => (+ StatusCode::INTERNAL_SERVER_ERROR,+ Json(ErrorResponse {+ message: "internal server error".into(),+ }),+ ),_ => (StatusCode::INTERNAL_SERVER_ERROR,Json(ErrorResponse {diff --git a/rust/cloud-storage/teams/src/inbound/axum_router/test.rs b/rust/cloud-storage/teams/src/inbound/axum_router/test.rsindex 27b39c281b..79775517d0 100644--- a/rust/cloud-storage/teams/src/inbound/axum_router/test.rs+++ b/rust/cloud-storage/teams/src/inbound/axum_router/test.rs@@ -1 +1,100 @@-// Tests for team handlers will be added once the full integration is complete.+use axum::{body::to_bytes, http::StatusCode, response::IntoResponse};+use serde_json::{Value, json};++use crate::domain::model::{+ CustomerError, DeleteTeamError, InviteUsersToTeamError, JoinTeamError, RemoveTeamInviteError,+ RemoveUserFromTeamError,+};++use super::invite_to_team::InviteToTeamError;++const CUSTOMER_ERROR_SENTINEL: &str = "sentinel customer repository failure";++fn customer_error() -> CustomerError {+ CustomerError::StorageLayerError(anyhow::anyhow!(CUSTOMER_ERROR_SENTINEL))+}++async fn response_parts(error: impl IntoResponse) -> (StatusCode, String, Value) {+ let response = error.into_response();+ let status = response.status();+ let body = to_bytes(response.into_body(), usize::MAX)+ .await+ .expect("error response body should be readable");+ let body_text = String::from_utf8(body.to_vec()).expect("error response body should be UTF-8");+ let body_json =+ serde_json::from_slice(&body).expect("error response body should contain valid JSON");++ (status, body_text, body_json)+}++async fn assert_customer_error_is_obfuscated(error: impl IntoResponse) {+ let (status, body_text, body_json) = response_parts(error).await;++ assert_eq!(status, StatusCode::INTERNAL_SERVER_ERROR);+ assert_eq!(body_text, r#"{"message":"internal server error"}"#);+ assert_eq!(body_json, json!({ "message": "internal server error" }));+ assert!(!body_text.contains(CUSTOMER_ERROR_SENTINEL));+}++#[tokio::test]+async fn delete_team_customer_error_response_is_obfuscated() {+ assert_customer_error_is_obfuscated(DeleteTeamError::CustomerError(customer_error())).await;+}++#[tokio::test]+async fn invite_users_to_team_customer_error_response_is_obfuscated() {+ assert_customer_error_is_obfuscated(InviteUsersToTeamError::CustomerError(customer_error()))+ .await;+}++#[tokio::test]+async fn invite_to_team_customer_error_response_is_obfuscated_but_display_retains_details() {+ let error = InviteToTeamError::InviteUsersToTeamError(InviteUsersToTeamError::CustomerError(+ customer_error(),+ ));++ assert!(error.to_string().contains(CUSTOMER_ERROR_SENTINEL));+ assert_customer_error_is_obfuscated(error).await;+}++#[tokio::test]+async fn join_team_customer_error_response_is_obfuscated() {+ assert_customer_error_is_obfuscated(JoinTeamError::CustomerError(customer_error())).await;+}++#[tokio::test]+async fn remove_team_invite_customer_error_response_is_obfuscated() {+ assert_customer_error_is_obfuscated(RemoveTeamInviteError::CustomerError(customer_error()))+ .await;+}++#[tokio::test]+async fn remove_user_from_team_customer_error_response_is_obfuscated() {+ assert_customer_error_is_obfuscated(RemoveUserFromTeamError::CustomerError(customer_error()))+ .await;+}++#[tokio::test]+async fn invite_to_team_validation_error_response_is_preserved() {+ let (status, body_text, _) = response_parts(InviteToTeamError::InvalidEmails).await;++ assert_eq!(status, StatusCode::BAD_REQUEST);+ assert_eq!(body_text, r#"{"message":"invalid emails detected"}"#);+}++#[tokio::test]+async fn remove_team_invite_not_found_response_is_preserved() {+ let (status, body_text, _) =+ response_parts(RemoveTeamInviteError::TeamInviteDoesNotExist).await;++ assert_eq!(status, StatusCode::NOT_FOUND);+ assert_eq!(body_text, r#"{"message":"team invite does not exist"}"#);+}++#[tokio::test]+async fn remove_team_owner_validation_response_is_preserved() {+ let (status, body_text, _) = response_parts(RemoveUserFromTeamError::CannotRemoveOwner).await;++ assert_eq!(status, StatusCode::BAD_REQUEST);+ assert_eq!(body_text, r#"{"message":"cannot remove owner"}"#);+}