Skip to content

fix(sync): (Codex) 规范化 Google Drive 和 OneDrive 的文件系统请求错误#1406

Open
cyfung1031 wants to merge 1 commit intomainfrom
fix/sync/012
Open

fix(sync): (Codex) 规范化 Google Drive 和 OneDrive 的文件系统请求错误#1406
cyfung1031 wants to merge 1 commit intomainfrom
fix/sync/012

Conversation

@cyfung1031
Copy link
Copy Markdown
Collaborator

概述

本 PR 新增一个轻量级的文件系统错误类型,并将其接入 Google Drive 和 OneDrive 的请求封装层。

主要改动:

  • 新增 FileSystemError,携带 providerstatuscoderetryableconflictauthnotFoundrateLimitraw 信息。
  • 新增错误判断辅助函数:
    • isNotFoundError
    • isConflictError
    • isRateLimitError
    • isAuthError
  • 将 Google Drive 的 HTTP/API 错误响应规范化为 FileSystemError
  • 将 OneDrive Graph 的 HTTP/API 错误响应规范化为 FileSystemError
  • 保留 Google Drive 和 OneDrive 现有的 token refresh 行为。
  • 保留 nothen 请求路径的原始 Response 返回行为,避免影响现有调用方。
  • 调整 OneDrive 目录创建逻辑,使其能识别 typed conflict error 下的“目录已存在”场景。
  • 补充 provider 测试,覆盖 auth retry、retry 后仍 auth 失败、404、409/412、429 等场景。

背景

后续 cloud sync 修复需要先有可靠的错误分类能力,例如:

  • Google Drive 在 provider 404 时清理 stale path cache 并重试。
  • 条件写入时识别 409/412 conflict。
  • 对 429 和 5xx 做更可靠的 retry/rate-limit 判断。
  • 区分 auth 失败、文件不存在、写入冲突和临时性失败。

在本 PR 之前,Google Drive 和 OneDrive 的请求封装会抛出由响应文本或 JSON 字符串构造的普通 Error。这会丢失 HTTP status/code 等结构化信息,上层只能依赖脆弱的字符串匹配。

行为变化

对于普通 JSON 请求路径:

  • HTTP/API 401 仍会尝试刷新 token 一次。
  • 如果刷新后仍然返回 401,会抛出 auth: trueFileSystemError
  • 404 会抛出 notFound: trueFileSystemError
  • 409 和 412 会抛出 conflict: trueFileSystemError
  • 429 会抛出 rateLimit: trueretryable: trueFileSystemError
  • 5xx 会标记为 retryable: true

刻意不改变的行为:

  • 使用 nothen 的调用仍然返回原始 Response。这样可以保持现有 delete/read 流程稳定,避免本 PR 扩大改动范围。
  • 保留现有 WarpTokenErrorWarpNetworkError 导出,避免影响 WebDAV、S3 和现有同步逻辑。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CloudSync Related to CloudSync

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant