import type { FunctionComponent } from 'react'; import { css } from '@patternfly/react-styles'; import { Content } from '@patternfly/react-core'; import { createUseStyles } from 'react-jss'; export interface ErrorStackProps { /** Error object to be displayed in the stack */ error: Error; /** Custom className */ className?: string; } const useStyles = createUseStyles({ errorStack: { fontFamily: 'monospace', fontSize: 'var(--pf-t--global--font--size--300)', textAlign: 'left', backgroundColor: 'white', borderStyle: 'solid', borderColor: 'var(--pf-t--color--gray--90)', overflowWrap: 'break-word', padding: 'var(--pf-t--global--spacer--200)' }, }) export const ErrorStack: FunctionComponent = ({ error, className, ...props }) => { const classes = useStyles(); if (error.stack) { return ( {error.stack.split('\n').map((line) => (
{line}
))}
); } if (error.name && error.message) { return ( <> {error.name} {error.message} ); } return ( {error.toString()} ); }; export default ErrorStack;