Skip to content

Commit b4fcf84

Browse files
committed
feat: show error when operation failed to revalidate
1 parent f9fc6c2 commit b4fcf84

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/components/viewer/OperationViewer.tsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { useOperation } from 'apis/query'
2020
import { apiPostRating } from 'apis/rating'
2121
import { useAtom } from 'jotai'
2222
import { noop } from 'lodash-es'
23-
import { ComponentType, FC, useMemo, useState } from 'react'
23+
import { ComponentType, FC, useEffect, useMemo, useState } from 'react'
2424
import { Link } from 'react-router-dom'
2525
import snakecaseKeys from 'snakecase-keys'
2626

@@ -44,6 +44,7 @@ import { CopilotDocV1 } from '../../models/copilot.schema'
4444
import { createCustomLevel, findLevelByStageName } from '../../models/level'
4545
import { Level } from '../../models/operation'
4646
import { toShortCode } from '../../models/shortCode'
47+
import { formatError } from '../../utils/error'
4748
import { ActionCard } from '../ActionCard'
4849
import { CommentArea } from './comment/CommentArea'
4950

@@ -123,19 +124,22 @@ export const OperationViewer: ComponentType<{
123124

124125
const [auth] = useAtom(authAtom)
125126

127+
// make eslint happy: we got Suspense out there
128+
if (!operation) return null
129+
126130
const operationDoc = useMemo(
127-
() => toCopilotOperation(operation!),
131+
() => toCopilotOperation(operation),
128132
[operation],
129133
)
130134

131-
// make eslint happy: we got Suspense out there
132-
if (!operation) return null
133-
134-
if (error) {
135-
return (
136-
<NonIdealState icon="error" title="获取作业失败" description={error} />
137-
)
138-
}
135+
useEffect(() => {
136+
if (error) {
137+
AppToaster.show({
138+
intent: 'danger',
139+
message: `刷新作业失败:${formatError(error)}`,
140+
})
141+
}
142+
}, [error])
139143

140144
const handleCopyShortCode = () => {
141145
const shortCode = toShortCode(operation.id)

0 commit comments

Comments
 (0)