@@ -265,50 +265,52 @@ export function isEntitlementError(code: string, bodyText: string): boolean {
265265 * @param bodyText - The response body text to inspect for workspace-related phrases
266266 * @returns `true` if the error indicates a disabled/expired workspace
267267 */
268- export function isWorkspaceDisabledError ( status : number , code : string , bodyText : string ) : boolean {
269- const haystack = `${ code } ${ bodyText } ` . toLowerCase ( ) ;
270-
271- // Check for HTTP 403 with workspace disabled messages
272- if ( status === 403 ) {
273- // Common patterns for disabled/expired workspaces
274- const disabledPatterns = [
275- / w o r k s p a c e .* (?: d i s a b l e d | e x p i r e d | d e a c t i v a t e d | t e r m i n a t e d ) / i,
276- / a c c o u n t .* (?: d i s a b l e d | e x p i r e d | d e a c t i v a t e d | t e r m i n a t e d ) / i,
277- / (?: w o r k s p a c e | a c c o u n t ) .* n o l o n g e r .* (?: a c t i v e | a v a i l a b l e | v a l i d ) / i,
278- / (?: w o r k s p a c e | a c c o u n t ) .* h a s b e e n .* (?: d i s a b l e d | e x p i r e d | c l o s e d ) / i,
279- / w o r k s p a c e .* (?: a c c e s s | s u b s c r i p t i o n ) .* e x p i r e d / i,
280- / b i l l i n g .* (?: f a i l e d | e x p i r e d | d i s a b l e d ) / i,
281- / p a y m e n t .* (?: f a i l e d | e x p i r e d | r e q u i r e d ) / i,
282- / o r g a n i z a t i o n .* (?: d i s a b l e d | e x p i r e d | i n a c t i v e ) / i,
283- / t e a m .* (?: d i s a b l e d | e x p i r e d | i n a c t i v e ) / i,
284- ] ;
285-
286- for ( const pattern of disabledPatterns ) {
287- if ( pattern . test ( haystack ) ) {
288- return true ;
289- }
290- }
268+ export function isWorkspaceDisabledError (
269+ status : number ,
270+ code : unknown ,
271+ bodyText : string ,
272+ ) : boolean {
273+ if ( status !== 403 ) {
274+ return false ;
291275 }
292-
293- // Check for specific error codes that indicate workspace issues.
294- if ( status === 403 ) {
295- const workspaceErrorCodes = [
296- "workspace_disabled" ,
297- "workspace_expired" ,
298- "workspace_terminated" ,
299- "account_disabled" ,
300- "account_expired" ,
301- "organization_disabled" ,
302- "billing_failed" ,
303- "payment_required" ,
304- ] ;
305-
306- if ( workspaceErrorCodes . some ( ( c ) => code . toLowerCase ( ) . includes ( c ) ) ) {
276+
277+ const normalizedCode = typeof code === "string" ? code . trim ( ) . toLowerCase ( ) : "" ;
278+ const haystack = `${ normalizedCode } ${ bodyText } ` . toLowerCase ( ) ;
279+
280+ const disabledPatterns = [
281+ / w o r k s p a c e .* (?: d i s a b l e d | e x p i r e d | d e a c t i v a t e d | t e r m i n a t e d ) / i,
282+ / a c c o u n t .* (?: d i s a b l e d | e x p i r e d | d e a c t i v a t e d | t e r m i n a t e d ) / i,
283+ / (?: w o r k s p a c e | a c c o u n t ) .* n o l o n g e r .* (?: a c t i v e | a v a i l a b l e | v a l i d ) / i,
284+ / (?: w o r k s p a c e | a c c o u n t ) .* h a s b e e n .* (?: d i s a b l e d | e x p i r e d | c l o s e d ) / i,
285+ / w o r k s p a c e .* (?: a c c e s s | s u b s c r i p t i o n ) .* e x p i r e d / i,
286+ / o r g a n i z a t i o n .* (?: d i s a b l e d | e x p i r e d | i n a c t i v e ) / i,
287+ / t e a m .* (?: d i s a b l e d | e x p i r e d | i n a c t i v e ) / i,
288+ ] ;
289+
290+ for ( const pattern of disabledPatterns ) {
291+ if ( pattern . test ( haystack ) ) {
307292 return true ;
308293 }
309294 }
310295
311- return false ;
296+ const workspaceErrorCodes = new Set ( [
297+ "workspace_disabled" ,
298+ "workspace_expired" ,
299+ "workspace_terminated" ,
300+ "account_disabled" ,
301+ "account_expired" ,
302+ "organization_disabled" ,
303+ ] ) ;
304+ if ( workspaceErrorCodes . has ( normalizedCode ) ) {
305+ return true ;
306+ }
307+
308+ const normalizedTokens = normalizedCode
309+ . split ( / [ ^ a - z 0 - 9 _ ] + / i)
310+ . map ( ( token ) => token . trim ( ) )
311+ . filter ( ( token ) => token . length > 0 ) ;
312+
313+ return normalizedTokens . some ( ( token ) => workspaceErrorCodes . has ( token ) ) ;
312314}
313315
314316/**
0 commit comments