@@ -304,6 +304,39 @@ const accountMetaLine = (account: AccountSummary): string | null => {
304304 return null ;
305305} ;
306306
307+ const DEFAULT_REFRESH_ERROR_MESSAGE = "Credits refresh failed." ;
308+
309+ const normalizeRefreshErrorMessage = ( value : string | null | undefined ) : string => {
310+ const trimmed = ( value ?? "" ) . trim ( ) ;
311+ return trimmed . length > 0 ? trimmed : DEFAULT_REFRESH_ERROR_MESSAGE ;
312+ } ;
313+
314+ const makeErroredCreditsInfo = ( message : string , previous ?: CreditsInfo ) : CreditsInfo => ( {
315+ available : null ,
316+ used : null ,
317+ total : null ,
318+ currency : previous ?. currency ?? "USD" ,
319+ source : previous ?. source ?? "wham_usage" ,
320+ mode : previous ?. mode ?? "balance" ,
321+ unit : previous ?. unit ?? "USD" ,
322+ planType : previous ?. planType ?? null ,
323+ isPaidPlan : previous ?. isPaidPlan ?? false ,
324+ hourlyRemainingPercent : null ,
325+ weeklyRemainingPercent : null ,
326+ hourlyRefreshAt : null ,
327+ weeklyRefreshAt : null ,
328+ status : "error" ,
329+ message : normalizeRefreshErrorMessage ( message ) ,
330+ checkedAt : nowEpoch ( ) ,
331+ } ) ;
332+
333+ const refreshErrorMessageForCredits = ( credits : CreditsInfo | undefined ) : string | null => {
334+ if ( ! credits || credits . status !== "error" ) {
335+ return null ;
336+ }
337+ return normalizeRefreshErrorMessage ( credits . message ) ;
338+ } ;
339+
307340const applyTheme = ( theme : Theme ) => {
308341 document . documentElement . dataset . theme = theme ;
309342 localStorage . setItem ( "codex-manager-theme" , theme ) ;
@@ -543,6 +576,15 @@ function App() {
543576 } ) ;
544577 } ;
545578
579+ const setAccountRefreshError = ( accountId : string , reason : unknown ) : string => {
580+ const message = normalizeRefreshErrorMessage ( reason instanceof Error ? reason . message : String ( reason ) ) ;
581+ setCreditsById ( ( current ) => ( {
582+ ...current ,
583+ [ accountId ] : makeErroredCreditsInfo ( message , current [ accountId ] ) ,
584+ } ) ) ;
585+ return message ;
586+ } ;
587+
546588 const accountStateForBucket = ( bucket : AccountBucket ) : AccountSummary [ "state" ] => {
547589 if ( bucket === "depleted" ) {
548590 return "archived" ;
@@ -710,8 +752,8 @@ function App() {
710752 failureMessages . push ( `Credits check issue: ${ credits . message } ` ) ;
711753 }
712754 } catch ( creditsError ) {
713- const rendered = creditsError instanceof Error ? creditsError . message : String ( creditsError ) ;
714- failureMessages . push ( rendered ) ;
755+ const message = setAccountRefreshError ( id , creditsError ) ;
756+ failureMessages . push ( `Credits check issue: ${ message } ` ) ;
715757 } finally {
716758 markRefreshing ( [ id ] , false ) ;
717759 }
@@ -747,6 +789,9 @@ function App() {
747789 } else {
748790 setError ( `Credits check issue: ${ credits . message } ` ) ;
749791 }
792+ } catch ( creditsError ) {
793+ const message = setAccountRefreshError ( id , creditsError ) ;
794+ setError ( `Credits check issue: ${ message } ` ) ;
750795 } finally {
751796 markRefreshing ( [ id ] , false ) ;
752797 }
@@ -1853,6 +1898,7 @@ function App() {
18531898 < For each = { activeAccounts ( ) } >
18541899 { ( account ) => {
18551900 const credits = ( ) => creditsById ( ) [ account . id ] ;
1901+ const refreshErrorMessage = ( ) => refreshErrorMessageForCredits ( credits ( ) ) ;
18561902 const refreshRows = ( ) => usageRefreshRows ( credits ( ) , nowTick ( ) , usageRefreshDisplayMode ( ) ) ;
18571903 const isCurrent = ( ) => view ( ) ?. activeAccountId === account . id ;
18581904
@@ -1874,7 +1920,12 @@ function App() {
18741920 < IconDragHandle />
18751921 </ span >
18761922 < div class = "account-main" >
1877- < p class = "account-title account-main-value" > { accountTitle ( account ) } </ p >
1923+ < p
1924+ class = { `account-title account-main-value ${ refreshErrorMessage ( ) ? "account-main-error" : "" } ` }
1925+ title = { refreshErrorMessage ( ) ?? undefined }
1926+ >
1927+ { accountTitle ( account ) }
1928+ </ p >
18781929 </ div >
18791930 < Show when = { isCurrent ( ) } >
18801931 < p class = "pill pill-active" > ACTIVE</ p >
@@ -2047,6 +2098,7 @@ function App() {
20472098 < For each = { depletedAccounts ( ) } >
20482099 { ( account ) => {
20492100 const credits = ( ) => creditsById ( ) [ account . id ] ;
2101+ const refreshErrorMessage = ( ) => refreshErrorMessageForCredits ( credits ( ) ) ;
20502102 const refreshRows = ( ) => usageRefreshRows ( credits ( ) , nowTick ( ) , usageRefreshDisplayMode ( ) ) ;
20512103
20522104 return (
@@ -2065,7 +2117,12 @@ function App() {
20652117 < IconDragHandle />
20662118 </ span >
20672119 < div class = "account-main" >
2068- < p class = "account-title account-main-value" > { accountTitle ( account ) } </ p >
2120+ < p
2121+ class = { `account-title account-main-value ${ refreshErrorMessage ( ) ? "account-main-error" : "" } ` }
2122+ title = { refreshErrorMessage ( ) ?? undefined }
2123+ >
2124+ { accountTitle ( account ) }
2125+ </ p >
20692126 </ div >
20702127 </ header >
20712128
@@ -2229,6 +2286,7 @@ function App() {
22292286 { ( account ) => {
22302287 const credits = ( ) => creditsById ( ) [ account . id ] ;
22312288 const availablePercent = ( ) => quotaRemainingPercent ( credits ( ) ) ;
2289+ const refreshErrorMessage = ( ) => refreshErrorMessageForCredits ( credits ( ) ) ;
22322290 const refreshRows = ( ) => usageRefreshRows ( credits ( ) , nowTick ( ) , usageRefreshDisplayMode ( ) ) ;
22332291
22342292 return (
@@ -2247,7 +2305,12 @@ function App() {
22472305 < IconDragHandle />
22482306 </ span >
22492307 < div class = "account-main" >
2250- < p class = "account-title account-main-value" > { accountTitle ( account ) } </ p >
2308+ < p
2309+ class = { `account-title account-main-value ${ refreshErrorMessage ( ) ? "account-main-error" : "" } ` }
2310+ title = { refreshErrorMessage ( ) ?? undefined }
2311+ >
2312+ { accountTitle ( account ) }
2313+ </ p >
22512314 </ div >
22522315 </ header >
22532316
0 commit comments