[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) <nim@odoo.com>
This commit is contained in:
Julien Castiaux
2019-05-27 06:41:56 +00:00
committed by Nicolas Martinelli
parent c868da4de6
commit 042966ccae
+7 -1
View File
@@ -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 {