[FIX] web: send array domains to the server in domain field
The `FieldDomain` was sending string domains instead of array domains to the server (by its associated `BasicModel._fetchSpecialDomain` function). The server does not do the conversion string -> array for domains, so the RPC broke everytime. This commit also modifies the `MockServer` so that tests also break when sending string domains. It also improves the way failed rpc are handled. Indeed when an rpc fails, its deferred is rejected with two arguments: the error object, and a JQuery event (that will display the error if not preventDefaulted). The mockRPC didn't pass the second one and thus there was a crash when reaching code that e.g. calls preventDefault on that event. Note: this also removes the stringify/parse of the error object as it is not a correct simulation of a server error object anyway.
This commit is contained in:
@@ -1551,7 +1551,7 @@ var BasicModel = AbstractModel.extend({
|
||||
var def = $.Deferred();
|
||||
|
||||
this._rpc(domainModel, "search_count")
|
||||
.args([domainValue])
|
||||
.args([Domain.prototype.stringToArray(domainValue)])
|
||||
.withContext(context)
|
||||
.exec()
|
||||
.then(_.identity, function (error, e) {
|
||||
|
||||
@@ -91,7 +91,12 @@ var MockServer = Class.extend({
|
||||
try {
|
||||
def = this._performRpc(route, args);
|
||||
} catch (error) {
|
||||
def = $.Deferred().reject(error);
|
||||
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.message, $.Event());
|
||||
}
|
||||
return def.then(function (result) {
|
||||
var resultString = JSON.stringify(result || false);
|
||||
@@ -101,14 +106,6 @@ var MockServer = Class.extend({
|
||||
console.log('%c[rpc] response:', 'color: blue; font-weight: bold;', JSON.parse(resultString));
|
||||
}
|
||||
return JSON.parse(resultString);
|
||||
}, function (error) {
|
||||
var errorString = JSON.stringify(error || false);
|
||||
if (logLevel === 1) {
|
||||
console.warn('Mock: ' + route, JSON.parse(errorString));
|
||||
} else if (logLevel === 2) {
|
||||
console.warn('%c[rpc] error response:', 'color: blue; font-weight: bold;', JSON.parse(errorString));
|
||||
}
|
||||
return JSON.parse(errorString);
|
||||
});
|
||||
},
|
||||
|
||||
@@ -230,6 +227,10 @@ var MockServer = Class.extend({
|
||||
* @returns {Object[]} a list of records
|
||||
*/
|
||||
_getRecords: function (model, domain) {
|
||||
if (!_.isArray(domain)) {
|
||||
throw new Error("MockServer._getRecords: given domain has to be an array.");
|
||||
}
|
||||
|
||||
var self = this;
|
||||
var records = this.data[model].records;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user