From 2ca4a957a5f5e17f0c508b4212f27657a85ec0c9 Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Sat, 15 Oct 2022 16:33:17 +0800 Subject: [PATCH] feat(OneDrive): show retry-after duration in error message if request is throttled, and mark such error as retryable. --- public/locales/en-US/application.json | 1 + public/locales/zh-CN/application.json | 1 + src/component/Uploader/core/errors/index.ts | 16 +++++++++++++++- src/component/Uploader/core/types.ts | 1 + 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/public/locales/en-US/application.json b/public/locales/en-US/application.json index f5a5186..bc47de0 100644 --- a/public/locales/en-US/application.json +++ b/public/locales/en-US/application.json @@ -298,6 +298,7 @@ "chunkUploadError": "Failed to upload chunk [{{index}}].", "conflictError": "The upload task for files with the same name is already being processed.", "chunkUploadErrorWithMsg": "Chunk upload failed: {{msg}}", + "chunkUploadErrorWithRetryAfter": "(Please retry after {{retryAfter}}s)", "emptyFileError": "Uploading empty files to OneDrive is not supported, please create empty files via the Create File button.", "finishUploadError": "Unable to complete file upload.", "finishUploadErrorWithMsg": "Unable to complete file upload: {{msg}}", diff --git a/public/locales/zh-CN/application.json b/public/locales/zh-CN/application.json index 3b72c4d..71f6c43 100644 --- a/public/locales/zh-CN/application.json +++ b/public/locales/zh-CN/application.json @@ -298,6 +298,7 @@ "chunkUploadError": "分片 [{{index}}] 上传失败", "conflictError": "同名文件的上传任务已经在处理中", "chunkUploadErrorWithMsg": "分片上传失败: {{msg}}", + "chunkUploadErrorWithRetryAfter": "(请在 {{retryAfter}} 秒后重试)", "emptyFileError": "暂不支持上传空文件至 OneDrive,请通过创建文件按钮创建空文件", "finishUploadError": "无法完成文件上传", "finishUploadErrorWithMsg": "无法完成文件上传: {{msg}}", diff --git a/src/component/Uploader/core/errors/index.ts b/src/component/Uploader/core/errors/index.ts index 4af87db..fc5a4ac 100644 --- a/src/component/Uploader/core/errors/index.ts +++ b/src/component/Uploader/core/errors/index.ts @@ -228,9 +228,23 @@ export class OneDriveChunkError extends UploaderError { } public Message(): string { - return i18next.t(`uploader.chunkUploadErrorWithMsg`, { + let msg = i18next.t(`uploader.chunkUploadErrorWithMsg`, { msg: this.message, }); + + if (this.response.error.retryAfterSeconds != undefined){ + msg += " "+i18next.t(`uploader.chunkUploadErrorWithRetryAfter`, { + retryAfter: this.response.error.retryAfterSeconds, + }) + } + + return msg; + } + + public Retryable(): boolean { + return ( + super.Retryable() || this.response.error.retryAfterSeconds != undefined + ); } } diff --git a/src/component/Uploader/core/types.ts b/src/component/Uploader/core/types.ts index 34fee0c..d13031e 100644 --- a/src/component/Uploader/core/types.ts +++ b/src/component/Uploader/core/types.ts @@ -76,6 +76,7 @@ export interface OneDriveError { innererror?: { code: string; }; + retryAfterSeconds?: number; }; }