From 3a73f2c3de7fe0a15d32fcb48b972b0bbc821a8b Mon Sep 17 00:00:00 2001 From: Johann150 Date: Thu, 20 Apr 2023 17:58:09 +0200 Subject: [PATCH] client: improve error message on failed upload Changelog: Fixed Ref: https://github.com/misskey-dev/misskey/issues/8574 --- locales/en-US.yml | 3 +++ packages/client/src/scripts/upload.ts | 12 ++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/locales/en-US.yml b/locales/en-US.yml index bee6111fc..fa0d9d28e 100644 --- a/locales/en-US.yml +++ b/locales/en-US.yml @@ -233,6 +233,9 @@ resetAreYouSure: "Really reset?" saved: "Saved" messaging: "Chat" upload: "Upload" +uploadFailed: "Upload failed" +uploadFailedDescription: "The file could not be uploaded." +uploadFailedSize: "The file is too large to be uploaded." keepOriginalUploading: "Keep original image" keepOriginalUploadingDescription: "Saves the originally uploaded image as-is. If turned\ \ off, a version to display on the web will be generated on upload." diff --git a/packages/client/src/scripts/upload.ts b/packages/client/src/scripts/upload.ts index 249663793..fd376b6ae 100644 --- a/packages/client/src/scripts/upload.ts +++ b/packages/client/src/scripts/upload.ts @@ -83,10 +83,18 @@ export function uploadFile( // TODO: 消すのではなくて再送できるようにしたい uploads.value = uploads.value.filter(x => x.id !== id); + let text = i18n.ts.uploadFailedDescription; + if (xhr.status == 413) { + // the file was too large + text = i18n.ts.uploadFailedSize; + } else if (xhr.response?.error?.message != null) { + text = xhr.response?.error?.message; + } + alert({ type: 'error', - title: 'Failed to upload', - text: `${JSON.stringify(ev.target?.response)}, ${JSON.stringify(xhr.response)}`, + title: i18n.ts.uploadFailed, + text, }); reject();