File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed
Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -191,17 +191,28 @@ export function MetricWidget({
191191 body : JSON . stringify ( propsRef . current ) ,
192192 signal : controller . signal ,
193193 } )
194- . then ( ( res ) => res . json ( ) as Promise < MetricWidgetActionResponse > )
194+ . then ( async ( res ) => {
195+ try {
196+ return ( await res . json ( ) ) as MetricWidgetActionResponse ;
197+ } catch {
198+ throw new Error ( `Request failed (${ res . status } )` ) ;
199+ }
200+ } )
195201 . then ( ( data ) => {
196202 if ( ! controller . signal . aborted ) {
197203 setResponse ( data ) ;
198204 setIsLoading ( false ) ;
199205 }
200206 } )
201207 . catch ( ( err ) => {
202- // Ignore aborted requests
203208 if ( err instanceof DOMException && err . name === "AbortError" ) return ;
204209 if ( ! controller . signal . aborted ) {
210+ // Only surface the error if there's no existing successful data to preserve
211+ setResponse ( ( prev ) =>
212+ prev ?. success
213+ ? prev
214+ : { success : false , error : err . message || "Network error" }
215+ ) ;
205216 setIsLoading ( false ) ;
206217 }
207218 } ) ;
You can’t perform that action at this time.
0 commit comments