11import { Badge , Box , Button , Flex , HStack , Icon , Stack , Text } from "@chakra-ui/react" ;
2- import { WarningIcon } from "@chakra-ui/icons" ;
3- import { getHttpStatusMessage , getGenericErrorMessage } from "./deliveryPreviewUtils" ;
2+ import {
3+ FeedErrorInfo ,
4+ getHttpStatusMessage ,
5+ getGenericErrorMessage ,
6+ } from "./deliveryPreviewUtils" ;
47
58const scrollToRequestHistory = ( ) => {
69 document . getElementById ( "request-history" ) ?. scrollIntoView ( { behavior : "smooth" } ) ;
@@ -16,26 +19,21 @@ interface FeedLevelStateDisplayProps {
1619 feedState : FeedState ;
1720}
1821
19- interface HttpStatusErrorDisplayProps {
20- statusCode : number ;
22+ interface FeedErrorDisplayProps {
23+ errorInfo : FeedErrorInfo ;
2124}
2225
23- const HttpStatusErrorDisplay = ( { statusCode } : HttpStatusErrorDisplayProps ) => {
24- const statusInfo = getHttpStatusMessage ( statusCode ) ;
25- const StatusIcon = statusInfo . icon ;
26+ const FeedErrorDisplay = ( { errorInfo } : FeedErrorDisplayProps ) => {
27+ const StatusIcon = errorInfo . icon ;
2628
2729 return (
2830 < Box
2931 role = "status"
3032 py = { 6 }
3133 px = { 4 }
3234 borderLeftWidth = "4px"
33- borderLeftColor = { `${ statusInfo . colorScheme } .400` }
34- bg = {
35- statusInfo . severity === "auth" || statusInfo . severity === "not-found"
36- ? `${ statusInfo . colorScheme } .900`
37- : undefined
38- }
35+ borderLeftColor = { `${ errorInfo . colorScheme } .400` }
36+ bg = { errorInfo . severity === "blocking" ? `${ errorInfo . colorScheme } .900` : undefined }
3937 >
4038 < Flex
4139 direction = { { base : "column" , sm : "row" } }
@@ -45,24 +43,24 @@ const HttpStatusErrorDisplay = ({ statusCode }: HttpStatusErrorDisplayProps) =>
4543 mb = { 3 }
4644 >
4745 < HStack spacing = { 2 } >
48- < Icon as = { StatusIcon } color = { `${ statusInfo . colorScheme } .400` } aria-hidden = "true" />
46+ < Icon as = { StatusIcon } color = { `${ errorInfo . colorScheme } .400` } aria-hidden = "true" />
4947 < Text fontWeight = "semibold" color = "white" >
50- { statusInfo . title }
48+ { errorInfo . title }
5149 </ Text >
5250 </ HStack >
5351 < Badge
54- colorScheme = { statusInfo . colorScheme }
55- variant = { statusInfo . badgeVariant }
52+ colorScheme = { errorInfo . colorScheme }
53+ variant = { errorInfo . badgeVariant }
5654 fontSize = "xs"
5755 fontFamily = "mono"
5856 >
59- HTTP { statusCode }
57+ { errorInfo . badgeText }
6058 </ Badge >
6159 </ Flex >
6260 < Stack spacing = { 2 } >
63- < Text color = "whiteAlpha.900" > { statusInfo . explanation } </ Text >
61+ < Text color = "whiteAlpha.900" > { errorInfo . explanation } </ Text >
6462 < Text fontSize = "sm" color = "whiteAlpha.800" >
65- { statusInfo . action }
63+ { errorInfo . action }
6664 </ Text >
6765 </ Stack >
6866 < Button
@@ -79,37 +77,6 @@ const HttpStatusErrorDisplay = ({ statusCode }: HttpStatusErrorDisplayProps) =>
7977 ) ;
8078} ;
8179
82- interface GenericErrorDisplayProps {
83- feedState : string ;
84- errorType ?: string ;
85- }
86-
87- const GenericErrorDisplay = ( { feedState, errorType } : GenericErrorDisplayProps ) => {
88- const errorInfo = getGenericErrorMessage ( feedState , errorType ) ;
89-
90- return (
91- < Box role = "status" py = { 6 } px = { 4 } borderLeftWidth = "4px" borderLeftColor = "red.400" >
92- < HStack spacing = { 2 } mb = { 3 } >
93- < Icon as = { WarningIcon } color = "red.400" aria-hidden = "true" />
94- < Text fontWeight = "semibold" color = "white" >
95- { errorInfo . title }
96- </ Text >
97- </ HStack >
98- < Text color = "whiteAlpha.900" > { errorInfo . explanation } </ Text >
99- < Button
100- onClick = { scrollToRequestHistory }
101- size = { { base : "md" , md : "sm" } }
102- width = { { base : "100%" , md : "auto" } }
103- variant = "outline"
104- mt = { 4 }
105- minH = "44px"
106- >
107- View Request History
108- </ Button >
109- </ Box >
110- ) ;
111- } ;
112-
11380export const FeedLevelStateDisplay = ( { feedState } : FeedLevelStateDisplayProps ) => {
11481 // Note: "unchanged" state is no longer a feed-level state.
11582 // When the feed is unchanged, the backend returns articles with FeedUnchanged outcome.
@@ -119,13 +86,15 @@ export const FeedLevelStateDisplay = ({ feedState }: FeedLevelStateDisplayProps)
11986 feedState . errorType === "bad-status-code" &&
12087 feedState . httpStatusCode
12188 ) {
122- return < HttpStatusErrorDisplay statusCode = { feedState . httpStatusCode } /> ;
89+ const errorInfo = getHttpStatusMessage ( feedState . httpStatusCode ) ;
90+
91+ return < FeedErrorDisplay errorInfo = { errorInfo } /> ;
12392 }
12493
12594 if ( feedState . state === "fetch-error" || feedState . state === "parse-error" ) {
126- return (
127- < GenericErrorDisplay feedState = { feedState . state } errorType = { feedState . errorType } />
128- ) ;
95+ const errorInfo = getGenericErrorMessage ( feedState . state , feedState . errorType ) ;
96+
97+ return < FeedErrorDisplay errorInfo = { errorInfo } /> ;
12998 }
13099
131100 return null ;
0 commit comments