From 7eda184589e875c945c8dfae0050f19f8b91d982 Mon Sep 17 00:00:00 2001 From: "Robin Lejeune (role)" Date: Mon, 6 Nov 2023 14:49:16 +0100 Subject: [PATCH] [FIX] web_editor, website: allow links to unreachable pages Since commit [1] removed `legacyRejectPromiseHandler()`, trying to edit a link leading to an HTTP error triggers an "Uncaught Promise" error. This commit makes sure such links do not cause a traceback: the link popover is just less detailed (no title, favicon). [1]: https://github.com/odoo/odoo/commit/fcb16a3b1bd373726ffb54f0fbe41fb6d1784769 task-3584686 closes odoo/odoo#141225 Signed-off-by: Quentin Smetz (qsm) --- .../js/wysiwyg/widgets/link_popover_widget.js | 7 +++++++ addons/website/static/tests/tours/link_tools.js | 17 ++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/addons/web_editor/static/src/js/wysiwyg/widgets/link_popover_widget.js b/addons/web_editor/static/src/js/wysiwyg/widgets/link_popover_widget.js index 3c6d2f4e78a..e0cefe2d649 100644 --- a/addons/web_editor/static/src/js/wysiwyg/widgets/link_popover_widget.js +++ b/addons/web_editor/static/src/js/wysiwyg/widgets/link_popover_widget.js @@ -261,6 +261,13 @@ export class LinkPopoverWidget { this.$urlLink.text(ogTitle ? ogTitle.getAttribute('content') : title.text.trim()); } this.$fullUrl.removeClass('d-none').addClass('o_we_webkit_box'); + }).catch(error => { + // HTML error codes should not prevent to edit the links, so we + // only check for proper instances of Error. + if (error instanceof Error) { + return Promise.reject(error); + } + }).finally(() => { this.$target.popover('update'); }); } diff --git a/addons/website/static/tests/tours/link_tools.js b/addons/website/static/tests/tours/link_tools.js index 5659721b3c7..ab63662bed6 100644 --- a/addons/website/static/tests/tours/link_tools.js +++ b/addons/website/static/tests/tours/link_tools.js @@ -305,9 +305,24 @@ wTourUtils.registerWebsitePreviewTour('link_tools', { trigger: "iframe .s_text_image p a[href='/contactus']:contains('/contactus')", run: () => null, }, + // 11. Add a link leading to a 404 page + { + content: "Enter a non-existent URL", + trigger: "#o_link_dialog_url_input", + run: "text /this-address-does-not-exist", + }, + { + content: "Check that the link's href was updated and click on it", + trigger: "iframe .s_text_image p a[href='/this-address-does-not-exist']", + }, + { + content: "Check popover content is up-to-date", + trigger: "iframe .popover div a:contains('/this-address-does-not-exist')", + isCheck: true, + }, ...wTourUtils.clickOnSave(), ...wTourUtils.clickOnEditAndWaitEditMode(), - // 11. Add mega menu with Cards template and edit URL on text-selected card. + // 12. Add mega menu with Cards template and edit URL on text-selected card. wTourUtils.clickOnElement("menu link", "iframe header .nav-item a"), wTourUtils.clickOnElement("'Edit menu' icon", "iframe .o_edit_menu_popover .fa-sitemap"), {