From 69ccdb059191dd56e2a1c8aca15f82cc5d0a0911 Mon Sep 17 00:00:00 2001 From: Gusted Date: Sun, 18 Jul 2021 04:25:32 +0000 Subject: [PATCH] Show error to user when USw returns error (#1286) Related USw commit: https://github.com/userstyles-world/userstyles.world/commit/d4306f2f717326d655ebfc7e3137e4db97aa0a37 Co-authored-by: tophf --- background/style-manager.js | 11 +++++++++-- edit/edit.js | 4 ++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/background/style-manager.js b/background/style-manager.js index e473b079..f0a7bd24 100644 --- a/background/style-manager.js +++ b/background/style-manager.js @@ -372,7 +372,7 @@ const styleMan = (() => { handleSave(await saveStyle(style), {reason: 'success-revoke', codeIsUpdated: true}); break; - case 'publish': + case 'publish': { if (!style._usw || !style._usw.token) { // Ensures just the style does have the _isUswLinked property as `true`. for (const {style: someStyle} of dataMap.values()) { @@ -406,8 +406,15 @@ const styleMan = (() => { } handleSave(await saveStyle(style), {reason: 'success-publishing', codeIsUpdated: true}); } - uploadStyle(style); + + const returnResult = await uploadStyle(style); + // USw prefix errors with `Error:`. + if (returnResult.startsWith('Error:')) { + style._usw.publishingError = returnResult; + handleSave(await saveStyle(style), {reason: 'publishing-failed', codeIsUpdated: true}); + } break; + } } }); } diff --git a/edit/edit.js b/edit/edit.js index 8fccc7ef..28d39457 100644 --- a/edit/edit.js +++ b/edit/edit.js @@ -65,6 +65,10 @@ msg.onExtension(request => { if (['success-publishing', 'success-revoke'].includes(request.reason)) { updateUI(newStyle); } + if (request.reason === 'publishing-failed') { + messageBoxProxy.alert(newStyle._usw.publishingError, 'pre', + 'UserStyles.world: ' + t('genericError')); + } }); } }