-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PLU-108: [ACTIONABLE-ERRORS] Add new error format (#299)
- Loading branch information
Showing
13 changed files
with
278 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { IStepError } from '@plumber/types' | ||
|
||
export default class StepError extends Error { | ||
constructor(error: IStepError, options?: ErrorOptions) { | ||
const computedMessage = JSON.stringify(error) | ||
super(computedMessage, options) | ||
this.name = this.constructor.name | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import type { IJSONObject } from '@plumber/types' | ||
|
||
import HttpError from '@/errors/http' | ||
import StepError from '@/errors/step' | ||
|
||
export function generateHttpStepError( | ||
error: HttpError, | ||
solution: string, | ||
position: number, | ||
appName: string, | ||
) { | ||
const stepErrorName = `Status code: ${error.response.status} (${error.response.statusText})` | ||
return new StepError( | ||
{ | ||
name: stepErrorName, | ||
solution, | ||
position: position.toString(), | ||
appName, | ||
details: error.details as IJSONObject, | ||
}, | ||
{ cause: error }, | ||
) | ||
} | ||
|
||
export function generateStepError( | ||
name: string, | ||
solution: string, | ||
position: number, | ||
appName: string, | ||
) { | ||
return new StepError({ | ||
name, | ||
solution, | ||
position: position.toString(), | ||
appName, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
packages/frontend/src/components/TestSubstep/ErrorResult.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { IStepError } from '@plumber/types' | ||
|
||
import { useCallback, useState } from 'react' | ||
import { Box, Collapse, Text } from '@chakra-ui/react' | ||
import { Badge, Button, Infobox } from '@opengovsg/design-system-react' | ||
import JSONViewer from 'components/JSONViewer' | ||
|
||
interface ErrorResultProps { | ||
errorDetails: IStepError | ||
} | ||
|
||
const contactPlumberMessage = | ||
'If this error still persists, contact us at [email protected].' | ||
|
||
export default function ErrorResult(props: ErrorResultProps) { | ||
const { errorDetails } = props | ||
const { name, solution, position, appName, details } = errorDetails | ||
const [isOpen, setIsOpen] = useState(false) | ||
const toggleDropdown = useCallback(() => { | ||
setIsOpen((value) => !value) | ||
}, []) | ||
|
||
return ( | ||
<Infobox variant="error"> | ||
<Box> | ||
<Badge | ||
mb={2} | ||
bg="interaction.critical-subtle.default" | ||
color="interaction.critical.default" | ||
> | ||
<Text>{`Step ${position}: ${appName} error`}</Text> | ||
</Badge> | ||
|
||
<Text mb={0.5} textStyle="subhead-1"> | ||
{name} | ||
</Text> | ||
|
||
<Text textStyle="body-1"> | ||
{solution} {contactPlumberMessage}{' '} | ||
{details && ( | ||
<> | ||
<Button | ||
onClick={toggleDropdown} | ||
variant="link" | ||
size="sm" | ||
sx={{ textDecoration: 'underline' }} | ||
> | ||
View http error details below. | ||
</Button> | ||
|
||
<Box> | ||
<Collapse in={isOpen}> | ||
<JSONViewer data={details}></JSONViewer> | ||
</Collapse> | ||
</Box> | ||
</> | ||
)} | ||
</Text> | ||
</Box> | ||
</Infobox> | ||
) | ||
} |
47 changes: 47 additions & 0 deletions
47
packages/frontend/src/components/TestSubstep/GenericErrorResult.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { IJSONObject } from '@plumber/types' | ||
|
||
import { useCallback, useState } from 'react' | ||
import { Box, Collapse, Text } from '@chakra-ui/react' | ||
import { Button, Infobox } from '@opengovsg/design-system-react' | ||
import JSONViewer from 'components/JSONViewer' | ||
|
||
interface GenericErrorResultProps { | ||
errorDetails: IJSONObject | ||
} | ||
|
||
export default function GenericErrorResult(props: GenericErrorResultProps) { | ||
const { errorDetails } = props | ||
const [isOpen, setIsOpen] = useState(false) | ||
const toggleDropdown = useCallback(() => { | ||
setIsOpen((value) => !value) | ||
}, []) | ||
|
||
return ( | ||
<Infobox variant="error"> | ||
<Box> | ||
<Text mb={2} textStyle="subhead-1"> | ||
We could not test this step | ||
</Text> | ||
|
||
<Text textStyle="body-1"> | ||
Check if you have configured the steps above correctly and retest. If | ||
this error still persists, contact us at [email protected].{' '} | ||
<Button | ||
onClick={toggleDropdown} | ||
variant="link" | ||
size="sm" | ||
sx={{ textDecoration: 'underline' }} | ||
> | ||
View error details below. | ||
</Button> | ||
</Text> | ||
|
||
<Box> | ||
<Collapse in={isOpen}> | ||
<JSONViewer data={errorDetails}></JSONViewer> | ||
</Collapse> | ||
</Box> | ||
</Box> | ||
</Infobox> | ||
) | ||
} |
Oops, something went wrong.