From abda3464edc40b624ee070a92ff506e708f13dc3 Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Thu, 17 May 2018 17:33:52 +0200 Subject: [PATCH] [FIX] web: get_file handles arbitrary AND serialized exceptions Commit bcd4c90 was intendend to make get_file handle uncaught/unserialized exceptions in the context of a http request The drawback is that when get_file received a serialized exception (route: /report/download) the JS modal was empty in that case This commit handles both the cases OPW 1848606 closes #24794 --- addons/web/static/src/js/framework/ajax.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/addons/web/static/src/js/framework/ajax.js b/addons/web/static/src/js/framework/ajax.js index 8f4138a6208..cac9a34a009 100644 --- a/addons/web/static/src/js/framework/ajax.js +++ b/addons/web/static/src/js/framework/ajax.js @@ -232,12 +232,20 @@ function get_file(options) { if (options.error) { var body = this.contentDocument.body; var nodes = body.children.length === 0 ? body.childNodes : body.children; - options.error({ - message: nodes.length > 1 ? nodes[1].textContent : '', - data: { - title: nodes.length > 0 ? nodes[0].textContent : '', - }, - }); + var errorParams = {}; + + try { // Case of a serialized Odoo Exception: It is Json Parsable + var node = nodes[1] || nodes[0]; + errorParams = JSON.parse(node.textContent); + } catch (e) { // Arbitrary uncaught python side exception + errorParams = { + message: nodes.length > 1 ? nodes[1].textContent : '', + data: { + title: nodes.length > 0 ? nodes[0].textContent : '', + } + } + } + options.error(errorParams); } } finally { complete();