From e8630b8bfc9ff7752e49ce741222a846657df8a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6?= Date: Wed, 10 Jan 2024 12:52:25 +0100 Subject: [PATCH] fix: properly handle chunk upload failure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ --- lib/uploader.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/uploader.ts b/lib/uploader.ts index 4c7b6636..2901ac29 100644 --- a/lib/uploader.ts +++ b/lib/uploader.ts @@ -223,8 +223,18 @@ export class Uploader { // Update upload progress on chunk completion .then(() => { upload.uploaded = upload.uploaded + maxChunkSize }) .catch((error) => { + if (error?.response?.status === 507) { + logger.error('Upload failed, not enough space on the server or quota exceeded. Cancelling the remaining chunks', { error, upload }) + upload.cancel() + upload.status = UploadStatus.FAILED + throw error + } + if (!(error instanceof CanceledError)) { - logger.error(`Chunk ${chunk + 1} ${bufferStart} - ${bufferEnd} uploading failed`) + logger.error(`Chunk ${chunk + 1} ${bufferStart} - ${bufferEnd} uploading failed`, { error, upload }) + // TODO: support retrying ? + // https://github.com/nextcloud-libraries/nextcloud-upload/issues/5 + upload.cancel() upload.status = UploadStatus.FAILED } throw error