Skip to content

feat: add retry to ErrorSummary #1690

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

Merged
merged 1 commit into from
May 23, 2022
Merged
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
9 changes: 9 additions & 0 deletions site/src/components/ErrorSummary/ErrorSummary.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { action } from "@storybook/addon-actions"
import { ComponentMeta, Story } from "@storybook/react"
import React from "react"
import { ErrorSummary, ErrorSummaryProps } from "./ErrorSummary"
Expand All @@ -14,4 +15,12 @@ WithError.args = {
error: new Error("Something went wrong!"),
}

export const WithRetry = Template.bind({})
WithRetry.args = {
error: new Error("Failed to fetch something!"),
retry: () => {
action("retry")
},
}

export const WithUndefined = Template.bind({})
27 changes: 18 additions & 9 deletions site/src/components/ErrorSummary/ErrorSummary.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
import Button from "@material-ui/core/Button"
import RefreshIcon from "@material-ui/icons/Refresh"
import React from "react"
import { Stack } from "../Stack/Stack"

const Language = {
unknownErrorMessage: "Unknown error",
retryMessage: "Retry",
unknownErrorMessage: "An unknown error has occurred",
}

export interface ErrorSummaryProps {
error: Error | unknown
retry?: () => void
}

export const ErrorSummary: React.FC<ErrorSummaryProps> = ({ error }) => {
// TODO: More interesting error page
export const ErrorSummary: React.FC<ErrorSummaryProps> = ({ error, retry }) => (
<Stack>
{!(error instanceof Error) ? <div>{Language.unknownErrorMessage}</div> : <div>{error.toString()}</div>}

if (!(error instanceof Error)) {
return <div>{Language.unknownErrorMessage}</div>
} else {
return <div>{error.toString()}</div>
}
}
{retry && (
<div>
<Button onClick={retry} startIcon={<RefreshIcon />} variant="outlined">
{Language.retryMessage}
</Button>
</div>
)}
</Stack>
)