From 47da0b04f0abd951dcb63e8a320f55b8ef089712 Mon Sep 17 00:00:00 2001 From: Zeu Capua Date: Fri, 27 Sep 2024 12:00:50 -0700 Subject: [PATCH 1/2] throw errors on insight creation failure --- pages/workspaces/[workspaceId]/contributor-insights/new.tsx | 2 +- pages/workspaces/[workspaceId]/repository-insights/new.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pages/workspaces/[workspaceId]/contributor-insights/new.tsx b/pages/workspaces/[workspaceId]/contributor-insights/new.tsx index 71c1536f3e..d2e7d64aea 100644 --- a/pages/workspaces/[workspaceId]/contributor-insights/new.tsx +++ b/pages/workspaces/[workspaceId]/contributor-insights/new.tsx @@ -116,7 +116,7 @@ export default function CreateContributorInsightPage({ if (error) { toast({ description: "An error has occurred. Try again.", variant: "danger" }); setLoading(false); - return; + throw new Error(`Error creating a contributor insight`, { cause: error }); } toast({ description: "Insight created! Redirecting...", variant: "success" }); diff --git a/pages/workspaces/[workspaceId]/repository-insights/new.tsx b/pages/workspaces/[workspaceId]/repository-insights/new.tsx index bf7ea68a09..fe7d05a8dd 100644 --- a/pages/workspaces/[workspaceId]/repository-insights/new.tsx +++ b/pages/workspaces/[workspaceId]/repository-insights/new.tsx @@ -72,7 +72,7 @@ const NewInsightPage = () => { if (error) { toast({ description: "An error has occurred. Try again.", variant: "danger" }); setLoading(false); - return; + throw new Error(`Error creating a repository insight`, { cause: error }); } toast({ description: "Insight created! Redirecting...", variant: "success" }); From d500c4c087e77ee1633601e98a394c510579c1fe Mon Sep 17 00:00:00 2001 From: Zeu Capua Date: Fri, 27 Sep 2024 13:08:36 -0700 Subject: [PATCH 2/2] use sentry captureException --- pages/workspaces/[workspaceId]/contributor-insights/new.tsx | 4 +++- pages/workspaces/[workspaceId]/repository-insights/new.tsx | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pages/workspaces/[workspaceId]/contributor-insights/new.tsx b/pages/workspaces/[workspaceId]/contributor-insights/new.tsx index d2e7d64aea..9160330692 100644 --- a/pages/workspaces/[workspaceId]/contributor-insights/new.tsx +++ b/pages/workspaces/[workspaceId]/contributor-insights/new.tsx @@ -3,6 +3,7 @@ import { useRouter } from "next/router"; import { GetServerSidePropsContext } from "next"; import { ComponentProps, useEffect, useState } from "react"; import { createPagesServerClient } from "@supabase/auth-helpers-nextjs"; +import { captureException } from "@sentry/nextjs"; import { fetchApiData } from "helpers/fetchApiData"; import { deleteCookie, setCookie } from "lib/utils/server/cookies"; import { WORKSPACE_ID_COOKIE_NAME } from "lib/utils/caching"; @@ -116,7 +117,8 @@ export default function CreateContributorInsightPage({ if (error) { toast({ description: "An error has occurred. Try again.", variant: "danger" }); setLoading(false); - throw new Error(`Error creating a contributor insight`, { cause: error }); + captureException(new Error(`Error creating a contributor insight`, { cause: error })); + return; } toast({ description: "Insight created! Redirecting...", variant: "success" }); diff --git a/pages/workspaces/[workspaceId]/repository-insights/new.tsx b/pages/workspaces/[workspaceId]/repository-insights/new.tsx index fe7d05a8dd..f5d9be3fe3 100644 --- a/pages/workspaces/[workspaceId]/repository-insights/new.tsx +++ b/pages/workspaces/[workspaceId]/repository-insights/new.tsx @@ -3,6 +3,7 @@ import { useRouter } from "next/router"; import { ComponentProps, useEffect, useState } from "react"; import { GetServerSidePropsContext } from "next"; import { createPagesServerClient } from "@supabase/auth-helpers-nextjs"; +import { captureException } from "@sentry/nextjs"; import useSupabaseAuth from "lib/hooks/useSupabaseAuth"; import { createRepositoryInsight } from "lib/utils/workspace-utils"; @@ -72,7 +73,8 @@ const NewInsightPage = () => { if (error) { toast({ description: "An error has occurred. Try again.", variant: "danger" }); setLoading(false); - throw new Error(`Error creating a repository insight`, { cause: error }); + captureException(new Error(`Error creating a repository insight`, { cause: error })); + return; } toast({ description: "Insight created! Redirecting...", variant: "success" });