Skip to content

Commit

Permalink
chore: detailed error response for get page view
Browse files Browse the repository at this point in the history
  • Loading branch information
khorshuheng committed Jan 15, 2025
1 parent c3bba77 commit 1ed6e3b
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 10 deletions.
3 changes: 2 additions & 1 deletion libs/database/src/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ pub async fn select_web_user_from_uid(pool: &PgPool, uid: i64) -> Result<AFWebUs
uid
)
.fetch_one(pool)
.await?;
.await
.map_err(|err| anyhow::anyhow!("Unable to get user detail for {}: {}", uid, err))?;

Ok(row)
}
17 changes: 15 additions & 2 deletions src/biz/collab/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,15 +377,28 @@ pub async fn get_latest_collab_folder(
workspace_id,
CollabType::Folder,
)
.await?;
.await
.map_err(|err| {
AppError::Internal(anyhow::anyhow!(
"Unable to retrieve workspace folder {}: {}",
workspace_id,
err
))
})?;
let folder = Folder::from_collab_doc_state(
folder_uid,
CollabOrigin::Server,
encoded_collab.into(),
workspace_id,
vec![],
)
.map_err(|e| AppError::Unhandled(e.to_string()))?;
.map_err(|e| {
AppError::Internal(anyhow::anyhow!(
"Unable to decode workspace folder {}: {}",
workspace_id,
e
))
})?;
Ok(folder)
}

Expand Down
65 changes: 58 additions & 7 deletions src/biz/workspace/page_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,15 @@ pub async fn get_page_view_collab(
Some(uid) => Some(select_web_user_from_uid(pg_pool, uid).await?),
None => None,
};
let publish_view_ids = select_published_view_ids_for_workspace(pg_pool, workspace_id).await?;
let publish_view_ids = select_published_view_ids_for_workspace(pg_pool, workspace_id)
.await
.map_err(|err| {
AppError::Internal(anyhow::anyhow!(
"Unable to obtain published view id for workspace {}: {}",
workspace_id,
err
))
})?;
let publish_view_ids: HashSet<String> = publish_view_ids
.into_iter()
.map(|id| id.to_string())
Expand Down Expand Up @@ -1353,16 +1361,38 @@ async fn get_page_collab_data_for_database(
workspace_id: Uuid,
view_id: &str,
) -> Result<PageCollabData, AppError> {
let ws_db_oid = select_workspace_database_oid(pg_pool, &workspace_id).await?;
let ws_db_oid = select_workspace_database_oid(pg_pool, &workspace_id)
.await
.map_err(|err| {
AppError::Internal(anyhow::anyhow!(
"Unable to find workspace database oid for {}: {}",
workspace_id,
err
))
})?;
let ws_db = get_latest_collab_encoded(
collab_access_control_storage,
GetCollabOrigin::User { uid },
&workspace_id.to_string(),
&ws_db_oid,
CollabType::WorkspaceDatabase,
)
.await?;
let ws_db_collab = collab_from_doc_state(ws_db.doc_state.to_vec(), &ws_db_oid)?;
.await
.map_err(|err| {
AppError::Internal(anyhow::anyhow!(
"Unable to get latest workspace database collab {}: {}",
&ws_db_oid,
err
))
})?;
let ws_db_collab =
collab_from_doc_state(ws_db.doc_state.to_vec(), &ws_db_oid).map_err(|err| {
AppError::Internal(anyhow::anyhow!(
"Unable to decode workspace database collab {}: {}",
&ws_db_oid,
err
))
})?;
let ws_db_body = WorkspaceDatabase::open(ws_db_collab).map_err(|err| {
AppError::Internal(anyhow!("Failed to open workspace database body: {}", err))
})?;
Expand All @@ -1382,7 +1412,14 @@ async fn get_page_collab_data_for_database(
&db_oid,
CollabType::Database,
)
.await?;
.await
.map_err(|err| {
AppError::Internal(anyhow::anyhow!(
"Unable to get latest database collab {}: {}",
&db_oid,
err
))
})?;
let db_collab = Collab::new_with_source(
CollabOrigin::Server,
&db_oid,
Expand Down Expand Up @@ -1448,7 +1485,14 @@ async fn get_page_collab_data_for_database(
.collect();
row_collabs
})
.await?;
.await
.map_err(|err| {
AppError::Internal(anyhow::anyhow!(
"Unable to get row data for database {}: {}",
&db_oid,
err
))
})?;

Ok(PageCollabData {
encoded_collab: db.doc_state.to_vec(),
Expand All @@ -1469,7 +1513,14 @@ async fn get_page_collab_data_for_document(
view_id,
CollabType::Document,
)
.await?;
.await
.map_err(|err| {
AppError::Internal(anyhow::anyhow!(
"Unable to get page collab data for {}: {}",
view_id,
err
))
})?;
Ok(PageCollabData {
encoded_collab: collab.doc_state.clone().to_vec(),
row_data: HashMap::default(),
Expand Down

0 comments on commit 1ed6e3b

Please sign in to comment.