Skip to content

Commit c60dad4

Browse files
authored
Present error to users if fetching entity details fails (#486)
* Update error component to show more details if present * Update dialog to handle errors * Pass any fetch errors to dialog components * Display any fetch errors for projects and pipelines and tweak loading state * Pass error object from all views
1 parent aa67bcf commit c60dad4

File tree

24 files changed

+83
-55
lines changed

24 files changed

+83
-55
lines changed

ui/src/components/info-dialog/info-dialog.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { useActivePage } from './useActivePage'
77

88
export const InfoDialog = ({ name, slug }: { name: string; slug: string }) => {
99
const { activePage, setActivePage } = useActivePage()
10-
const { page, isLoading } = usePageDetails(slug)
10+
const { page, isLoading, error } = usePageDetails(slug)
1111

1212
return (
1313
<Dialog.Root
@@ -20,6 +20,7 @@ export const InfoDialog = ({ name, slug }: { name: string; slug: string }) => {
2020
<Dialog.Content
2121
ariaCloselabel={translate(STRING.CLOSE)}
2222
isLoading={isLoading}
23+
error={error}
2324
>
2425
<Dialog.Header title={name} />
2526
{page ? (

ui/src/design-system/components/dialog/dialog.module.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ $dialog-padding-medium: 32px;
111111
}
112112
}
113113

114+
.errorContent {
115+
padding: 32px;
116+
}
117+
114118
@media only screen and (max-width: $medium-screen-breakpoint) {
115119
.dialog {
116120
max-width: calc(100% - (2 * $dialog-padding-medium));

ui/src/design-system/components/dialog/dialog.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as Dialog from '@radix-ui/react-dialog'
22
import classNames from 'classnames'
3+
import { Error } from 'pages/error/error'
34
import { ReactNode } from 'react'
45
import { Icon, IconType } from '../icon/icon'
56
import { LoadingSpinner } from '../loading-spinner/loading-spinner'
@@ -28,12 +29,14 @@ const Content = ({
2829
children,
2930
isCompact,
3031
isLoading,
32+
error,
3133
onOpenAutoFocus,
3234
}: {
3335
ariaCloselabel: string
3436
children: ReactNode
3537
isCompact?: boolean
3638
isLoading?: boolean
39+
error?: any
3740
onOpenAutoFocus?: (event: Event) => void
3841
}) => (
3942
<Dialog.Portal>
@@ -46,12 +49,20 @@ const Content = ({
4649
</Dialog.Overlay>
4750
<Dialog.Content
4851
className={classNames(styles.dialog, {
49-
[styles.compact]: isCompact,
52+
[styles.compact]: isCompact || error,
5053
[styles.loading]: isLoading,
5154
})}
5255
onOpenAutoFocus={onOpenAutoFocus}
5356
>
54-
<div className={styles.dialogContent}>{children}</div>
57+
<div className={styles.dialogContent}>
58+
{error ? (
59+
<div className={styles.errorContent}>
60+
<Error error={error} />
61+
</div>
62+
) : (
63+
children
64+
)}
65+
</div>
5566
<Dialog.Close className={styles.dialogClose} aria-label={ariaCloselabel}>
5667
<Icon type={IconType.Close} size={12} />
5768
</Dialog.Close>

ui/src/pages/collection-details/collection-details.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const CollectionDetails = () => {
5050
})
5151

5252
if (!isLoading && error) {
53-
return <Error />
53+
return <Error error={error} />
5454
}
5555

5656
return (

ui/src/pages/deployment-details/deployment-details-dialog.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const DeploymentDetailsDialog = ({ id }: { id: string }) => {
1616
const navigate = useNavigate()
1717
const { projectId } = useParams()
1818
const { setDetailBreadcrumb } = useContext(BreadcrumbContext)
19-
const { deployment, isLoading } = useDeploymentDetails(id)
19+
const { deployment, isLoading, error } = useDeploymentDetails(id)
2020

2121
useEffect(() => {
2222
setDetailBreadcrumb(deployment ? { title: deployment.name } : undefined)
@@ -41,6 +41,7 @@ export const DeploymentDetailsDialog = ({ id }: { id: string }) => {
4141
<Dialog.Content
4242
ariaCloselabel={translate(STRING.CLOSE)}
4343
isLoading={isLoading}
44+
error={error}
4445
>
4546
{deployment ? (
4647
<DeploymentDetailsDialogContent deployment={deployment} />

ui/src/pages/deployments/deployments.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const Deployments = () => {
2424
const canCreate = userPermissions?.includes(UserPermission.Create)
2525

2626
if (!isLoading && error) {
27-
return <Error />
27+
return <Error error={error} />
2828
}
2929

3030
return (

ui/src/pages/error/error.module.scss

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
@import 'src/design-system/variables/variables.scss';
21
@import 'src/design-system/variables/colors.scss';
32
@import 'src/design-system/variables/typography.scss';
43

@@ -17,9 +16,3 @@
1716
border-radius: 8px;
1817
border: 1px solid $color-neutral-100;
1918
}
20-
21-
@media only screen and (max-width: $small-screen-breakpoint) {
22-
.wrapper {
23-
margin: 32px 16px;
24-
}
25-
}

ui/src/pages/error/error.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ import styles from './error.module.scss'
22

33
interface ErrorProps {
44
message?: string
5-
details?: string
5+
error?: any
66
}
77

88
export const Error = ({
99
message = 'Something went wrong!',
10-
details = 'Unknown error',
10+
error,
1111
}: ErrorProps) => {
12+
const details =
13+
error?.response?.data?.detail ?? error?.message ?? 'Unknown error'
14+
1215
return (
1316
<div className={styles.wrapper}>
1417
<h1 className={styles.message}>{message} 🪲</h1>

ui/src/pages/jobs/jobs.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const Jobs = () => {
3333
const canCreate = userPermissions?.includes(UserPermission.Create)
3434

3535
if (!isLoading && error) {
36-
return <Error />
36+
return <Error error={error} />
3737
}
3838

3939
return (
@@ -74,7 +74,7 @@ const JobDetailsDialog = ({ id }: { id: string }) => {
7474
const navigate = useNavigate()
7575
const { projectId } = useParams()
7676
const { setDetailBreadcrumb } = useContext(BreadcrumbContext)
77-
const { job, isLoading, isFetching } = useJobDetails(id)
77+
const { job, isLoading, isFetching, error } = useJobDetails(id)
7878

7979
useEffect(() => {
8080
setDetailBreadcrumb(job ? { title: job.name } : undefined)
@@ -97,6 +97,7 @@ const JobDetailsDialog = ({ id }: { id: string }) => {
9797
<Dialog.Content
9898
ariaCloselabel={translate(STRING.CLOSE)}
9999
isLoading={isLoading}
100+
error={error}
100101
>
101102
{job ? (
102103
<JobDetails

ui/src/pages/occurrences/occurrences.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export const Occurrences = () => {
5353
const { selectedView, setSelectedView } = useSelectedView('table')
5454

5555
if (!isLoading && error) {
56-
return <Error />
56+
return <Error error={error} />
5757
}
5858

5959
return (
@@ -125,7 +125,7 @@ const OccurrenceDetailsDialog = ({ id }: { id: string }) => {
125125
const navigate = useNavigate()
126126
const { projectId } = useParams()
127127
const { setDetailBreadcrumb } = useContext(BreadcrumbContext)
128-
const { occurrence, isLoading } = useOccurrenceDetails(id)
128+
const { occurrence, isLoading, error } = useOccurrenceDetails(id)
129129

130130
useEffect(() => {
131131
setDetailBreadcrumb(
@@ -152,6 +152,7 @@ const OccurrenceDetailsDialog = ({ id }: { id: string }) => {
152152
<Dialog.Content
153153
ariaCloselabel={translate(STRING.CLOSE)}
154154
isLoading={isLoading}
155+
error={error}
155156
>
156157
{occurrence ? <OccurrenceDetails occurrence={occurrence} /> : null}
157158
</Dialog.Content>

0 commit comments

Comments
 (0)