diff options
| author | Lucas Perais (lpe) <lpe@odoo.com> | 2018-05-17 17:33:52 +0200 |
|---|---|---|
| committer | Lucas Perais (lpe) <lpe@odoo.com> | 2018-05-18 13:03:31 +0200 |
| commit | abda3464edc40b624ee070a92ff506e708f13dc3 (patch) | |
| tree | b7ac409d798f0ad8ed39136f62cee415ea6df1a1 /addons/web/static/src | |
| parent | a16114efb43da7a14113b061b2ed0f110b668c74 (diff) | |
[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
Diffstat (limited to 'addons/web/static/src')
| -rw-r--r-- | addons/web/static/src/js/framework/ajax.js | 20 |
1 files 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(); |
