From 042966ccae3270a1119c4c5dcb095753cd6b784f Mon Sep 17 00:00:00 2001 From: Julien Castiaux Date: Fri, 24 May 2019 13:37:20 +0000 Subject: [PATCH] [IMP] web: better logging of errors When an error is raised server-side, the complete traceback is displayed in the JS console. This traceback can be very useful since it might contain information not recorded anywhere else by default. For example, access errors due to record rules or SQL constrains do not have their traceback displayed in the UI or recorded in the log [1], but it is logged in the JS console. However, the information is logged in the JS console as a stringified version of the `result.error` object. The final result is a long and non-formatted string which is unreadable. We replace by a new format more convenient for technical teams. The error is now formatted as: Error code Error message Error data message Error data debug This will hopefully give a better starting point for debugging purposes. [1] SQL constrains tracebacks are only recorded in the log in debug mode: https://github.com/odoo/odoo/blob/ec792da72b92b22349b6f325e53fd37d953c7db3/odoo/service/model.py#L122 closes odoo/odoo#33650 Signed-off-by: Nicolas Martinelli (nim) --- addons/web/static/src/js/core/ajax.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/js/core/ajax.js b/addons/web/static/src/js/core/ajax.js index f1f73bb5a28..cbd02e0755e 100644 --- a/addons/web/static/src/js/core/ajax.js +++ b/addons/web/static/src/js/core/ajax.js @@ -22,7 +22,13 @@ function genericJsonRpc (fct_name, params, settings, fct) { core.bus.trigger('rpc:result', data, result); if (result.error !== undefined) { if (result.error.data.arguments[0] !== "bus.Bus not available in test mode") { - console.error("Server application error", JSON.stringify(result.error)); + console.error( + "Server application error\n", + "Error code:", result.error.code, "\n", + "Error message:", result.error.message, "\n", + "Error data message:\n", result.error.data.message, "\n", + "Error data debug:\n", result.error.data.debug + ); } return $.Deferred().reject("server", result.error); } else {