@@ -98,17 +98,22 @@ function classifyGoogleDriveError(
9898
9999export class GoogleDriveApiError extends Error {
100100 retryAfterMs ?: number
101+ readonly reasons : readonly string [ ]
102+ readonly kind : GoogleDriveErrorKind
101103 readonly rateLimited : boolean
102104
103105 constructor (
104106 readonly status : number ,
105- readonly reasons : readonly string [ ] ,
106- readonly kind : GoogleDriveErrorKind
107+ normalizedReasons : readonly string [ ]
107108 ) {
108- const reasonSuffix = reasons . length > 0 ? ` (${ reasons . join ( ', ' ) } )` : ''
109+ const diagnosticReasons = normalizedReasons . slice ( 0 , GOOGLE_ERROR_REASON_MAX_COUNT )
110+ const reasonSuffix = diagnosticReasons . length > 0 ? ` (${ diagnosticReasons . join ( ', ' ) } )` : ''
109111 super ( `Google Drive API request failed with HTTP ${ status } ${ reasonSuffix } ` )
110112 this . name = 'GoogleDriveApiError'
111- this . rateLimited = status === 429 || reasons . some ( ( reason ) => RATE_LIMIT_REASONS . has ( reason ) )
113+ this . reasons = diagnosticReasons
114+ this . kind = classifyGoogleDriveError ( status , normalizedReasons )
115+ this . rateLimited =
116+ status === 429 || normalizedReasons . some ( ( reason ) => RATE_LIMIT_REASONS . has ( reason ) )
112117 }
113118}
114119
@@ -131,13 +136,8 @@ export async function readGoogleDriveApiError(response: Response): Promise<Googl
131136
132137 const entries = parsedBody ?. error ?. errors ?? [ ]
133138 const rawReasons = [ ...new Set ( entries . flatMap ( ( entry ) => ( entry . reason ? [ entry . reason ] : [ ] ) ) ) ]
134- const reasons = [ ...new Set ( rawReasons . flatMap ( ( reason ) => normalizeReason ( reason ) ?? [ ] ) ) ] . slice (
135- 0 ,
136- GOOGLE_ERROR_REASON_MAX_COUNT
137- )
138- return new GoogleDriveApiError (
139- response . status ,
140- reasons ,
141- classifyGoogleDriveError ( response . status , rawReasons )
142- )
139+ const normalizedReasons = [
140+ ...new Set ( rawReasons . flatMap ( ( reason ) => normalizeReason ( reason ) ?? [ ] ) ) ,
141+ ]
142+ return new GoogleDriveApiError ( response . status , normalizedReasons )
143143}
0 commit comments