Skip to content

Commit 97e82d8

Browse files
committed
fix(office-excel): delegate to parseGraphErrorFromData and handle array embed param
1 parent e9004cb commit 97e82d8

2 files changed

Lines changed: 4 additions & 42 deletions

File tree

apps/sim/app/chat/[identifier]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default async function ChatPage({
1515
}) {
1616
const { identifier } = await params
1717
const { embed } = await searchParams
18-
const isOfficeEmbed = embed === 'office'
18+
const isOfficeEmbed = embed === 'office' || (Array.isArray(embed) && embed.includes('office'))
1919

2020
return (
2121
<>

apps/sim/tools/error-extractors.ts

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* 2. Add the ID to ErrorExtractorId constant at the bottom of this file
2020
*/
2121

22+
import { parseGraphErrorFromData } from '@/tools/microsoft_excel/utils'
23+
2224
export interface ErrorInfo {
2325
status?: number
2426
statusText?: string
@@ -189,47 +191,7 @@ const ERROR_EXTRACTORS: ErrorExtractorConfig[] = [
189191
description:
190192
'Microsoft Graph error format with nested innerError chain and details[] (Excel, OneDrive, SharePoint, Outlook). See https://learn.microsoft.com/en-us/graph/errors',
191193
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),
233195
},
234196
{
235197
id: 'nested-error-object',

0 commit comments

Comments
 (0)