error handling

This commit is contained in:
Saxon Fletcher committed 2025-06-17 13:39:32 +10:00
1 parent b6368974a6
commit cb845534b2
4 files changed
+38 -14

No files matched your search

@@ -40,7 +40,7 @@ export async function getBranchDiff({
return diffData || ''
} catch (error) {
handleError(error)
throw error
return ''
}
}
@@ -54,10 +54,8 @@ export async function getEdgeFunctionBody(
const { files } = await parseResponse.json()
return files as EdgeFunctionFile[]
} catch (error) {
console.error('Failed to parse edge function code:', error)
throw new Error(
'Failed to parse function code. The file may be corrupted or in an invalid format.'
)
handleError(error)
return []
}
}
@@ -1,5 +1,6 @@
import { useMemo } from 'react'
import { useQueries } from '@tanstack/react-query'
import { handleError } from 'data/fetchers'
import {
getEdgeFunctionBody,
type EdgeFunctionBodyData,
@@ -104,6 +105,18 @@ export const useEdgeFunctionsDiff = ({
...removedBodiesQueries,
].some((q) => q.isLoading)
// Aggregate errors across all queries and handle the first encountered error.
const firstError = [
...currentBodiesQueries,
...mainBodiesQueries,
...addedBodiesQueries,
...removedBodiesQueries,
].find((q) => q.error)?.error
if (firstError) {
handleError(firstError)
}
// Build lookup maps --------------------------------------------------------
const currentBodiesMap: Record<string, EdgeFunctionBodyData | undefined> = {}
currentBodiesQueries.forEach((q, idx) => {
+22 -9
View File
@@ -30,9 +30,13 @@ const MergePage: NextPageWithLayout = () => {
const { ref } = useParams()
const gitlessBranching = useFlag('gitlessBranching')
if (!gitlessBranching) {
router.push(`/project/${ref}/branches`)
}
// Redirect to branches page if feature flag disabled
useEffect(() => {
if (!gitlessBranching && ref) {
router.push(`/project/${ref}/branches`)
}
}, [gitlessBranching, ref, router])
const project = useSelectedProject()
const [isSubmitting, setIsSubmitting] = useState(false)
@@ -41,7 +45,10 @@ const MergePage: NextPageWithLayout = () => {
const parentProjectRef = project?.parent_project_ref
// Get branch information
const { data: branches } = useBranchesQuery({ projectRef: parentProjectRef })
const { data: branches } = useBranchesQuery(
{ projectRef: parentProjectRef },
{ enabled: gitlessBranching && !!parentProjectRef }
)
const currentBranch = branches?.find((branch) => branch.project_ref === ref)
const mainBranch = branches?.find((branch) => branch.is_default)
@@ -53,7 +60,7 @@ const MergePage: NextPageWithLayout = () => {
const { data: workflowRuns } = useWorkflowRunsQuery(
{ projectRef: parentProjectRef },
{
enabled: !!parentProjectRef && !!workflowRunId,
enabled: gitlessBranching && !!parentProjectRef && !!workflowRunId,
refetchInterval: 3000, // Poll every 3 seconds to check for status changes
}
)
@@ -73,7 +80,7 @@ const MergePage: NextPageWithLayout = () => {
const { data: workflowRunLogs } = useWorkflowRunQuery(
{ workflowRunId },
{
enabled: !!workflowRunId,
enabled: gitlessBranching && !!workflowRunId,
refetchInterval: isPolling ? 2000 : false, // Poll logs every 2 seconds until complete
}
)
@@ -89,7 +96,7 @@ const MergePage: NextPageWithLayout = () => {
branchId: currentBranch?.id || '',
projectRef: parentProjectRef || '',
},
{ enabled: !!currentBranch?.id }
{ enabled: gitlessBranching && !!currentBranch?.id }
)
// Show toast notifications when workflow status changes
@@ -119,11 +126,11 @@ const MergePage: NextPageWithLayout = () => {
// Get edge functions for both branches
const { data: currentBranchFunctions, isLoading: isCurrentFunctionsLoading } =
useEdgeFunctionsQuery({ projectRef: ref }, { enabled: !!ref })
useEdgeFunctionsQuery({ projectRef: ref }, { enabled: gitlessBranching && !!ref })
const { data: mainBranchFunctions, isLoading: isMainFunctionsLoading } = useEdgeFunctionsQuery(
{ projectRef: parentProjectRef },
{ enabled: !!parentProjectRef }
{ enabled: gitlessBranching && !!parentProjectRef }
)
// Check if there are any changes (database or edge functions)
@@ -238,6 +245,7 @@ const MergePage: NextPageWithLayout = () => {
]
}, [workflowRunId, currentTab])
// If not on a preview branch or branch info unavailable, show notice
if (!isBranch || !currentBranch) {
return (
<PageLayout title="Merge Request">
@@ -248,6 +256,11 @@ const MergePage: NextPageWithLayout = () => {
)
}
if (!gitlessBranching) {
// Render nothing while redirecting
return null
}
const isDataLoaded = !isDiffLoading && !isCurrentFunctionsLoading && !isMainFunctionsLoading
const isMergeDisabled = hasAnyChanges && isDataLoaded