Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui: refine handle errors #602

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ui/dashboardApp/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ function initAxios() {
singleSpa.navigateToUrl('#' + auth.signInRoute)
err.handled = true
} else if (err.message === 'Network Error') {
message.error(i18next.t('error.message.network'))
const content = i18next.t('error.message.network')
message.error({ content, key: 'network_error' }) // use key to avoid multiple message boxes
err.handled = true
err.msg = content // use `err.message` doesn't work
}
return Promise.reject(err)
})
Expand Down
4 changes: 3 additions & 1 deletion ui/lib/apps/Overview/components/Instances.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import {
import client from '@lib/client'
import { AnimatedSkeleton, Card } from '@lib/components'
import { useClientRequest } from '@lib/utils/useClientRequest'
import getApiErrorsMsg from '@lib/utils/apiErrorsMsg'

export default function Instances() {
const { t } = useTranslation()
const { data, isLoading, error } = useClientRequest((cancelToken) =>
client.getInstance().topologyAllGet({ cancelToken })
)
const errorMsg = useMemo(() => getApiErrorsMsg([error]), [error])

const statusMap = useMemo(() => {
if (!data) {
Expand Down Expand Up @@ -66,7 +68,7 @@ export default function Instances() {
noMarginLeft
>
<AnimatedSkeleton showSkeleton={isLoading}>
{error && <Alert message="Error" type="error" showIcon />}
{error && <Alert message={errorMsg} type="error" showIcon />}
{data &&
statusMap.map((s) => {
return (
Expand Down
31 changes: 14 additions & 17 deletions ui/lib/components/CardTableV2/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,23 +204,20 @@ function CardTableV2(props: ICardTableV2Props) {
<AnimatedSkeleton
showSkeleton={items.length === 0 && loading && !errorMsg}
>
{errorMsg ? (
<Alert message={errorMsg} type="error" showIcon />
) : (
<div className={styles.cardTableContent}>
<MemoDetailsList
selectionMode={SelectionMode.none}
constrainMode={ConstrainMode.unconstrained}
layoutMode={DetailsListLayoutMode.justified}
onRenderDetailsHeader={renderStickyHeader}
onRenderRow={onRowClicked ? renderClickableRow : undefined}
onRenderCheckbox={onRenderCheckbox}
columns={finalColumns}
items={finalItems}
{...restProps}
/>
</div>
)}
{errorMsg && <Alert message={errorMsg} type="error" showIcon />}
<div className={styles.cardTableContent}>
<MemoDetailsList
selectionMode={SelectionMode.none}
constrainMode={ConstrainMode.unconstrained}
layoutMode={DetailsListLayoutMode.justified}
onRenderDetailsHeader={renderStickyHeader}
onRenderRow={onRowClicked ? renderClickableRow : undefined}
onRenderCheckbox={onRenderCheckbox}
columns={finalColumns}
items={finalItems}
{...restProps}
/>
</div>
</AnimatedSkeleton>
</Card>
)
Expand Down
2 changes: 1 addition & 1 deletion ui/lib/components/MetricChart/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export default function MetricChart({
) {
inner = (
<div style={{ height: HEIGHT }}>
<Alert message={errorMsg || 'Error'} type="error" showIcon />
<Alert message={errorMsg} type="error" showIcon />
</div>
)
} else {
Expand Down
4 changes: 2 additions & 2 deletions ui/lib/utils/apiErrorsMsg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import _ from 'lodash'

export default function getApiErrorsMsg(errors: any[]) {
return _.uniq(
_.map(errors, (err) => err?.response?.data?.message || '')
).join('; ')
_.map(errors, (err) => err?.response?.data?.message || err?.msg || '')
)[0]
}