From fcc3ada247c66f69371092c406fcc6b1eb5b21b1 Mon Sep 17 00:00:00 2001 From: Joel Low Date: Fri, 19 Mar 2021 16:23:54 +0800 Subject: [PATCH] feat(errors): Reuse ResponseErrorList for non ResponseErrors Signed-off-by: Joel Low --- .changeset/shy-owls-grab.md | 5 + .../ResponseErrorPanel/ResponseErrorPanel.tsx | 136 +++++++++++------- 2 files changed, 89 insertions(+), 52 deletions(-) create mode 100644 .changeset/shy-owls-grab.md diff --git a/.changeset/shy-owls-grab.md b/.changeset/shy-owls-grab.md new file mode 100644 index 0000000000..ccee56c153 --- /dev/null +++ b/.changeset/shy-owls-grab.md @@ -0,0 +1,5 @@ +--- +'@backstage/core': patch +--- + +Reuse ResponseErrorList for non ResponseErrors diff --git a/packages/core/src/components/ResponseErrorPanel/ResponseErrorPanel.tsx b/packages/core/src/components/ResponseErrorPanel/ResponseErrorPanel.tsx index c36be78f08..52f7ab03f9 100644 --- a/packages/core/src/components/ResponseErrorPanel/ResponseErrorPanel.tsx +++ b/packages/core/src/components/ResponseErrorPanel/ResponseErrorPanel.tsx @@ -39,6 +39,78 @@ const useStyles = makeStyles(theme => ({ }, })); +type ResponseErrorListProps = { + error: string; + message: string; + request?: string; + stack?: string; + json?: string; +}; + +const ResponseErrorList = ({ + error, + request, + message, + stack, + json, +}: ResponseErrorListProps) => { + const classes = useStyles(); + + return ( + + + + + + + + + + {request && ( + + + + + )} + {stack && ( + + + + + )} + {json && ( + <> + + + } + /> + + + + )} + + ); +}; + type Props = { error: Error; }; @@ -50,13 +122,13 @@ type Props = { * server-provided information about what happened. */ export const ResponseErrorDetails = ({ error }: Props) => { - const classes = useStyles(); - if (error.name !== 'ResponseError') { return ( - - - + ); } @@ -70,53 +142,13 @@ export const ResponseErrorDetails = ({ error }: Props) => { const jsonString = JSON.stringify(data, undefined, 2); return ( - - - - - - - - - - {requestString && ( - - - - - )} - {stackString && ( - - - - - )} - - - } - /> - - - + ); };