From 6e2d810bb4b30da67748ee410e232c9a884d2888 Mon Sep 17 00:00:00 2001 From: "Randall Castro - https://www.vauxoo.com" Date: Tue, 26 Aug 2025 04:04:54 +0000 Subject: [PATCH] [REF] Task{Comment,Info} handling Error handling in both TaskComment and TaskInfo is now improved - Add more specific error messages (e.g., include context like "Failed to update comment" or "Failed to assign user"). - Log errors to the console for debugging. - Ensure all errors are surfaced to the user (no silent failures). - Errors are logged to the console for easier debugging. - Silent failures are avoided; users always get actionable feedback. --- apps/web/src/components/task/task-comment.tsx | 20 +++++++----- apps/web/src/components/task/task-info.tsx | 32 ++++++++++++++----- 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/apps/web/src/components/task/task-comment.tsx b/apps/web/src/components/task/task-comment.tsx index 5d813adb..af483ec0 100644 --- a/apps/web/src/components/task/task-comment.tsx +++ b/apps/web/src/components/task/task-comment.tsx @@ -42,6 +42,7 @@ function TaskComment({ async function handleSubmit(data: z.infer) { if (!user?.id) { + toast.error("You must be logged in to add or update a comment."); return; } @@ -52,6 +53,7 @@ function TaskComment({ userId: user.id, content: data.comment, }); + toast.success("Comment updated successfully."); onSubmit?.(); } else { await createComment({ @@ -59,6 +61,7 @@ function TaskComment({ content: data.comment, userId: user?.id, }); + toast.success("Comment added successfully."); onSubmit?.(); } @@ -66,16 +69,17 @@ function TaskComment({ queryKey: ["activities", taskId], }); - toast.success( - commentId - ? "Comment updated successfully" - : "Comment added successfully", - ); form.reset(); } catch (error) { - toast.error( - error instanceof Error ? error.message : "Failed to add comment", - ); + // Log error for debugging + console.error("TaskComment error:", error); + let message = "Unable to submit your comment. Please try again or contact support."; + if (error instanceof Error) { + message = error.message; + } else if (typeof error === "string") { + message = error; + } + toast.error(message); } } diff --git a/apps/web/src/components/task/task-info.tsx b/apps/web/src/components/task/task-info.tsx index 40208a37..54a4051f 100644 --- a/apps/web/src/components/task/task-info.tsx +++ b/apps/web/src/components/task/task-info.tsx @@ -65,7 +65,10 @@ function TaskInfo({ }); const handleChange = async (data: z.infer) => { - if (!task) return; + if (!task) { + toast.error("No task found. Unable to update."); + return; + } setIsSaving(true); try { @@ -79,16 +82,24 @@ function TaskInfo({ }); toast.success("Task updated successfully"); } catch (error) { - toast.error( - error instanceof Error ? error.message : "Failed to update task", - ); + console.error("Error updating task:", error); + let message = "An unexpected error occurred while updating the task."; + if (error instanceof Error) { + message = error.message; + } else if (typeof error === "string") { + message = error; + } + toast.error(message); } finally { setIsSaving(false); } }; const handleDeleteTask = async () => { - if (!task) return; + if (!task) { + toast.error("No task found. Unable to delete."); + return; + } try { await deleteTask(task.id); @@ -104,9 +115,14 @@ function TaskInfo({ }, }); } catch (error) { - toast.error( - error instanceof Error ? error.message : "Failed to delete task", - ); + console.error("Error deleting task:", error); + let message = "An unexpected error occurred while deleting the task."; + if (error instanceof Error) { + message = error.message; + } else if (typeof error === "string") { + message = error; + } + toast.error(message); } };