[FIX] web: mock server should not catch errors

Otherwise some changes can create rpc errors that are silently caught
and never seen as long as, out of (un)luck, the end result is the same.

Tests which need to create a server error can just simulate it using
the mockRPC mechanism.
This commit is contained in:
David Monjoie
2017-06-02 11:06:44 +02:00
parent 719e040dee
commit 6d75ccdb59
3 changed files with 13 additions and 14 deletions
+1 -13
View File
@@ -95,19 +95,7 @@ var MockServer = Class.extend({
if (logLevel === 2) {
console.log('%c[rpc] request ' + route, 'color: blue; font-weight: bold;', args);
}
var def;
try {
def = this._performRpc(route, args);
} catch (e) {
var error = {code: 200, data: {}, message: e.message};
if (logLevel === 1) {
console.warn('Mock: ' + route, error.message);
} else if (logLevel === 2) {
console.warn('%c[rpc] error response:', 'color: blue; font-weight: bold;', error.message);
}
return $.Deferred().reject(error, $.Event());
}
return def.then(function (result) {
return this._performRpc(route, args).then(function (result) {
var resultString = JSON.stringify(result || false);
if (logLevel === 1) {
console.log('Mock: ' + route, JSON.parse(resultString));
@@ -4839,6 +4839,13 @@ QUnit.module('Views', {
if (args.method === 'search_count') {
assert.strictEqual(args.model, 'test',
"should search_count on test");
if (!args.kwargs.domain) {
return $.Deferred().reject({
code: 200,
data: {},
message: "MockServer._getRecords: given domain has to be an array.",
}, $.Event());
}
}
return this._super.apply(this, arguments);
},
@@ -391,7 +391,11 @@ QUnit.module('Views', {
groupBy: ['product_id'],
mockRPC: function (route, args) {
if (args.method === 'name_create') {
throw new Error("Odoo server error");
return $.Deferred().reject({
code: 200,
data: {},
message: "Odoo server error",
}, $.Event());
}
return this._super.apply(this, arguments);
},