|
19 | 19 | * 2. Add the ID to ErrorExtractorId constant at the bottom of this file |
20 | 20 | */ |
21 | 21 |
|
| 22 | +import { parseGraphErrorFromData } from '@/tools/microsoft_excel/utils' |
| 23 | + |
22 | 24 | export interface ErrorInfo { |
23 | 25 | status?: number |
24 | 26 | statusText?: string |
@@ -189,47 +191,7 @@ const ERROR_EXTRACTORS: ErrorExtractorConfig[] = [ |
189 | 191 | description: |
190 | 192 | 'Microsoft Graph error format with nested innerError chain and details[] (Excel, OneDrive, SharePoint, Outlook). See https://learn.microsoft.com/en-us/graph/errors', |
191 | 193 | examples: ['Microsoft Excel', 'Microsoft OneDrive', 'Microsoft SharePoint'], |
192 | | - extract: (errorInfo) => { |
193 | | - const data = errorInfo?.data |
194 | | - if (!data || typeof data !== 'object') return undefined |
195 | | - |
196 | | - const root = (data as { error?: any }).error |
197 | | - if (root && typeof root === 'object') { |
198 | | - const messages: string[] = [] |
199 | | - if (typeof root.message === 'string' && root.message.trim()) { |
200 | | - messages.push(root.message.trim()) |
201 | | - } |
202 | | - |
203 | | - // Walk nested innerError chain. Spec uses `innererror` (lowercase), |
204 | | - // Graph commonly returns `innerError` — accept both. Cap depth. |
205 | | - let inner: any = root.innererror ?? root.innerError |
206 | | - let depth = 0 |
207 | | - while (inner && depth < 5) { |
208 | | - if (typeof inner.message === 'string' && inner.message.trim()) { |
209 | | - const msg = inner.message.trim() |
210 | | - if (!messages.includes(msg)) messages.push(msg) |
211 | | - } |
212 | | - inner = inner.innererror ?? inner.innerError |
213 | | - depth++ |
214 | | - } |
215 | | - |
216 | | - if (Array.isArray(root.details)) { |
217 | | - for (const detail of root.details) { |
218 | | - if (detail && typeof detail.message === 'string' && detail.message.trim()) { |
219 | | - const msg = detail.message.trim() |
220 | | - if (!messages.includes(msg)) messages.push(msg) |
221 | | - } |
222 | | - } |
223 | | - } |
224 | | - |
225 | | - if (messages.length > 0) return messages.join(' — ') |
226 | | - if (typeof root.code === 'string' && root.code.trim()) return root.code.trim() |
227 | | - } |
228 | | - |
229 | | - const topMessage = (data as { message?: unknown }).message |
230 | | - if (typeof topMessage === 'string' && topMessage.trim()) return topMessage.trim() |
231 | | - return undefined |
232 | | - }, |
| 194 | + extract: (errorInfo) => parseGraphErrorFromData(errorInfo?.data), |
233 | 195 | }, |
234 | 196 | { |
235 | 197 | id: 'nested-error-object', |
|
0 commit comments