Budibase/budibase · error · HTTPError

Failed to fetch SharePoint drive item (${response.status})

Error message

Failed to fetch SharePoint drive item (${response.status})

What it means

Thrown when a Microsoft Graph API call to fetch a SharePoint drive item returns a non-ok response that is not 401/403/404. The status code is embedded in the message and it is wrapped as an HTTPError with status 400. It exists to surface unexpected Graph failures (rate limits, 5xx, malformed requests) with a clear SharePoint-specific message.

Source

Thrown at packages/server/src/sdk/workspace/ai/knowledgeSources/sharepoint/connection.ts:811

        `${SHAREPOINT_API_BASE}/drives/${encodeURIComponent(
          driveId
        )}/items/${encodeURIComponent(
          itemId
        )}?$select=id,name,eTag,lastModifiedDateTime,size,file,folder,parentReference`,
        {
          signal,
          headers: {
            Authorization: bearerToken,
          },
        }
      ),
    signal
  )
  if (response.status === 404) {
    return undefined
  }
  if (!response.ok) {
    throw new HTTPError(
      response.status === 401 || response.status === 403
        ? "Access denied by Microsoft Graph. Ensure delegated SharePoint read permissions are granted."
        : `Failed to fetch SharePoint drive item (${response.status})`,
      400
    )
  }
  return (await response.json()) as SharePointDriveItem
}

export const collectSharePointFilesRecursive = async (
  bearerToken: string,
  driveId: string,
  folderId?: string,
  parentPath = "",
  signal?: AbortSignal
): Promise<SharePointFileRef[]> => {
  const items = await listSharePointDriveItems(
    bearerToken,

View on GitHub (pinned to a81a902e9a)

Solutions

  1. Check the status code in the message: retry with backoff if 429/5xx (Graph throttling is common on bulk operations)
  2. Verify the driveId and itemId used in the Graph call still exist via GET /drives/{driveId}/items/{itemId}
  3. Inspect console/server logs for the underlying Graph response body to see the detailed error code
  4. Re-run the knowledge source sync after confirming the Graph API status at https://status.microsoft.com

Example fix

// before: single attempt, throws on 429
const item = await fetchDriveItem(connection, driveId, itemId, signal)
// after: retry throttled/transient responses
async function fetchWithRetry(url: string, init: RequestInit, attempts = 3) {
  for (let i = 0; i < attempts; i++) {
    const res = await fetch(url, init)
    if (res.status === 429 || res.status >= 500) {
      await new Promise(r => setTimeout(r, 2 ** i * 1000))
      continue
    }
    return res
  }
  throw new HTTPError("Failed to fetch SharePoint drive item after retries", 400)
}
Defensive patterns

Strategy: retry

Validate before calling

// pre-flight: verify drive item accessibility
const head = await fetch(`https://graph.microsoft.com/v1.0/drives/${driveId}/items/${itemId}`, { headers: { Authorization: `Bearer ${token}` }, method: "GET" })
if (!head.ok && head.status !== 404) throw new Error(`Graph pre-check failed: ${head.status}`)

Try / catch

try {
  await fetchDriveItem(conn, driveId, itemId, signal)
} catch (e) {
  if (e instanceof HTTPError && /Failed to fetch SharePoint drive item \(429\)|\(5\d\d\)/.test(e.message)) {
    await sleep(backoff(attempt)); return retry()
  }
  throw e
}

Prevention

When it happens

Trigger: Calling the SharePoint knowledge-source connection which issues a Graph GET for a drive item and receives e.g. 429 (throttled), 500/503 (Graph outage), or 400 (bad driveId/itemId format). 404 returns undefined and 401/403 produce the access-denied message instead.

Common situations: Graph service degradation or throttling during large bulk syncs; a stale or deleted drive/item id cached in the knowledge source config; an incorrectly constructed Graph URL from a malformed site/drive identifier.

Related errors


AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29). Data as JSON: /api/errors/207ddd7efe9a73ed. Report an issue: GitHub.