summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/services/crash_manager.js
diff options
context:
space:
mode:
authorfja-odoo <fja@odoo.com>2019-06-11 12:26:45 +0000
committerfja-odoo <fja@odoo.com>2019-06-28 08:53:52 +0000
commitf8fe314e786d2100833ecc8b0cb661252f648ddc (patch)
tree0198886f7856f105a0654bfbb95154e0e9804341 /addons/web/static/src/js/services/crash_manager.js
parente6d4ab84da7a1031ab552b4a6b3fc4aa2348163e (diff)
[IMP] web, *: display warning/error in frontend
* = account, iap, point_of_sale Removing the CrashManager templates from base.xml and moving it to a new file (crash_manager.xml) to allow lazy loading the required xml only when a crash occurs (necessary for the frontend as no xml is pre-loaded). All rpc errors/warnings are now displayed using the same modal system as the backend (crash_manager.js). CrashManager will now return the WarningDialog and ErrorDialog in addition to the CrashManager itself. In some cases an instance of CrashManager was created just to display a warning/error dialog. In the backend all rpc errors but sessionExpired will be logged. If the exception is a warning, NotFound (403) or except_orm, it will be a warning log. The rest will be exception log. In the frontend all rpc errors will be logged using console.debug instead of console.warn and console.error. This way we can trigger rpc errors in tests without failing them. If a real error happend during a test it will fall back on the backend logger to fail the test. Part of https://github.com/odoo/odoo/pull/32132 task-1894820
Diffstat (limited to 'addons/web/static/src/js/services/crash_manager.js')
-rw-r--r--addons/web/static/src/js/services/crash_manager.js126
1 files changed, 94 insertions, 32 deletions
diff --git a/addons/web/static/src/js/services/crash_manager.js b/addons/web/static/src/js/services/crash_manager.js
index 7b3469e5e47..8681a869aba 100644
--- a/addons/web/static/src/js/services/crash_manager.js
+++ b/addons/web/static/src/js/services/crash_manager.js
@@ -4,21 +4,76 @@ odoo.define('web.CrashManager', function (require) {
var ajax = require('web.ajax');
var core = require('web.core');
var Dialog = require('web.Dialog');
+var Widget = require('web.Widget');
-var QWeb = core.qweb;
var _t = core._t;
var _lt = core._lt;
var map_title ={
- user_error: _lt('Warning'),
- warning: _lt('Warning'),
- access_error: _lt('Access Error'),
- missing_error: _lt('Missing Record'),
- validation_error: _lt('Validation Error'),
- except_orm: _lt('Global Business Error'),
- access_denied: _lt('Access Denied'),
+ user_error: _lt("User Error"),
+ warning: _lt("Warning"),
+ access_error: _lt("Access Error"),
+ missing_error: _lt("Missing Record"),
+ validation_error: _lt("Validation Error"),
+ except_orm: _lt("Global Business Error"),
+ access_denied: _lt("Access Denied"),
};
+/**
+ * An extension of Dialog Widget to render the warnings and errors on the website.
+ * Extend it with your template of choice like ErrorDialog/WarningDialog
+ */
+var CrashManagerDialog = Dialog.extend({
+ xmlDependencies: (Dialog.prototype.xmlDependencies || []).concat(
+ ['/web/static/src/xml/crash_manager.xml']
+ ),
+
+ /**
+ * @param {Object} error
+ * @param {string} error.message the message in Warning/Error Dialog
+ * @param {string} error.traceback the traceback in ErrorDialog
+ *
+ * @constructor
+ */
+ init: function (parent, options, error) {
+ this._super.apply(this, [parent, options]);
+ this.message = error.message;
+ this.traceback = error.traceback;
+ },
+});
+
+var ErrorDialog = CrashManagerDialog.extend({
+ template: 'CrashManager.error',
+});
+
+var WarningDialog = CrashManagerDialog.extend({
+ template: 'CrashManager.warning',
+
+ /**
+ * Sets size to medium by default.
+ *
+ * @override
+ */
+ init: function (parent, options, error) {
+ this._super(parent, _.extend({
+ size: 'medium',
+ }, options), error);
+ },
+
+ //--------------------------------------------------------------------------
+ // Public
+ //--------------------------------------------------------------------------
+
+ /**
+ * Focuses the ok button.
+ *
+ * @override
+ */
+ open: function () {
+ this._super({shouldFocusButtons: true});
+ },
+});
+
var CrashManager = core.Class.extend({
init: function () {
var self = this;
@@ -129,8 +184,8 @@ var CrashManager = core.Class.extend({
return;
}
if (_.has(map_title, error.data.exception_type)) {
- if(error.data.exception_type === 'except_orm'){
- if(error.data.arguments[1]) {
+ if (error.data.exception_type === 'except_orm') {
+ if (error.data.arguments[1]) {
error = _.extend({}, error,
{
data: _.extend({}, error.data,
@@ -169,26 +224,30 @@ var CrashManager = core.Class.extend({
this.show_error(error);
}
},
- show_warning: function(error) {
+ show_warning: function (error) {
if (!this.active) {
return;
}
- return new Dialog(this, {
- size: 'medium',
- title: _.str.capitalize(error.type || error.message) || _t("Odoo Warning"),
+ var message = error.data ? error.data.message : error.message;
+ return new WarningDialog(this, {
+ title: _.str.capitalize(error.type) || _t("Odoo Warning"),
subtitle: error.data.title,
- $content: $(QWeb.render('CrashManager.warning', {error: error}))
- }).open({shouldFocusButtons:true});
+ }, {
+ message: message,
+ }).open();
},
- show_error: function(error) {
+ show_error: function (error) {
if (!this.active) {
return;
}
- var dialog = new Dialog(this, {
- title: _.str.capitalize(error.type || error.message) || _t("Odoo Error"),
- $content: $(QWeb.render('CrashManager.error', {error: error}))
+ var dialog = new ErrorDialog(this, {
+ title: _.str.capitalize(error.type) || _t("Odoo Error"),
+ }, {
+ message: error.message,
+ traceback: error.data.debug,
});
+
// When the dialog opens, initialize the copy feature and destroy it when the dialog is closed
var $clipboardBtn;
var clipboard;
@@ -256,7 +315,7 @@ var ExceptionHandler = {
* Handle redirection warnings, which behave more or less like a regular
* warning, with an additional redirection button.
*/
-var RedirectWarningHandler = Dialog.extend(ExceptionHandler, {
+var RedirectWarningHandler = Widget.extend(ExceptionHandler, {
init: function(parent, error) {
this._super(parent);
this.error = error;
@@ -264,10 +323,8 @@ var RedirectWarningHandler = Dialog.extend(ExceptionHandler, {
display: function() {
var self = this;
var error = this.error;
- error.data.message = error.data.arguments[0];
- new Dialog(this, {
- size: 'medium',
+ new WarningDialog(this, {
title: _.str.capitalize(error.type) || _t("Odoo Warning"),
buttons: [
{text: error.data.arguments[2], classes : "btn-primary", click: function() {
@@ -279,8 +336,9 @@ var RedirectWarningHandler = Dialog.extend(ExceptionHandler, {
location.reload();
}},
{text: _t("Cancel"), click: function() { self.destroy(); }, close: true}
- ],
- $content: QWeb.render('CrashManager.warning', {error: error}),
+ ]
+ }, {
+ message: error.data.arguments[0],
}).open();
}
});
@@ -290,9 +348,9 @@ core.crash_registry.add('odoo.exceptions.RedirectWarning', RedirectWarningHandle
function session_expired(cm) {
return {
display: function () {
- cm.show_warning({type: _t("Odoo Session Expired"), data: {message: _t("Your Odoo session expired. Please refresh the current web page.")}});
+ cm.show_warning({type: _t("Odoo Session Expired"), message: _t("Your Odoo session expired. Please refresh the current web page.")});
}
- }
+ };
}
core.crash_registry.add('odoo.http.SessionExpiredException', session_expired);
core.crash_registry.add('werkzeug.exceptions.Forbidden', session_expired);
@@ -302,18 +360,22 @@ core.crash_registry.add('504', function (cm) {
display: function () {
cm.show_warning({
type: _t("Request timeout"),
- data: {message: _t("The operation was interrupted. This usually means that the current operation is taking too much time.")}});
+ message: _t("The operation was interrupted. This usually means that the current operation is taking too much time.")});
}
- }
+ };
});
-return CrashManager;
+return {
+ CrashManager: CrashManager,
+ ErrorDialog: ErrorDialog,
+ WarningDialog: WarningDialog,
+};
});
odoo.define('web.crash_manager', function (require) {
"use strict";
-var CrashManager = require('web.CrashManager');
+var CrashManager = require('web.CrashManager').CrashManager;
return new CrashManager();
});