Throw deferred on synchronous RPC with error
The caller needs to know if the error management succeeded or not in order to redo the call. We can not redo the call inside the error management because this will break the synchronous property. issue9938 review335361002
This commit is contained in:
1 parent
e0b986037b
commit
bb39b7d452
2 files changed
+30
-17
No files matched your search
+7
-1
@@ -580,7 +580,13 @@
|
||||
this.id = this.model.execute(
|
||||
'create', [[values]], context, false)[0];
|
||||
} catch (e) {
|
||||
return jQuery.Deferred().reject();
|
||||
if (e.promise) {
|
||||
return e.then(function() {
|
||||
return this.save(force_reload);
|
||||
}.bind(this));
|
||||
} else {
|
||||
return jQuery.Deferred().reject();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!jQuery.isEmptyObject(values)) {
|
||||
|
||||
+23
-16
@@ -33,8 +33,8 @@
|
||||
var ajax_success = function(data, status_, query) {
|
||||
if (data === null) {
|
||||
Sao.common.warning.run('',
|
||||
Sao.i18n.gettext('Unable to reach the server.'));
|
||||
dfd.reject();
|
||||
Sao.i18n.gettext('Unable to reach the server.'))
|
||||
.always(dfd.reject);
|
||||
} else if (data.error) {
|
||||
var name, msg, description;
|
||||
if (data.error[0] == 'UserWarning') {
|
||||
@@ -55,11 +55,14 @@
|
||||
'always': result == 'always'
|
||||
}], {}]
|
||||
}, session).done(function() {
|
||||
Sao.rpc(args, session).then(
|
||||
dfd.resolve, dfd.reject);
|
||||
if (async) {
|
||||
Sao.rpc(args, session).then(
|
||||
dfd.resolve, dfd.reject);
|
||||
} else {
|
||||
dfd.resolve();
|
||||
}
|
||||
});
|
||||
}, dfd.reject);
|
||||
return;
|
||||
} else if (data.error[0] == 'UserError') {
|
||||
msg = data.error[1][0];
|
||||
description = data.error[1][1];
|
||||
@@ -74,9 +77,9 @@
|
||||
}
|
||||
Sao.common.warning.run(description, msg)
|
||||
.always(dfd.reject);
|
||||
return;
|
||||
} else if (data.error[0] == 'ConcurrencyException') {
|
||||
if (args.method.startsWith('model.') &&
|
||||
if (async &&
|
||||
args.method.startsWith('model.') &&
|
||||
(args.method.endsWith('.write') ||
|
||||
args.method.endsWith('.delete')) &&
|
||||
(args.params[0].length == 1)) {
|
||||
@@ -88,16 +91,14 @@
|
||||
Sao.rpc(args, session).then(
|
||||
dfd.resolve, dfd.reject);
|
||||
}, dfd.reject);
|
||||
return;
|
||||
} else {
|
||||
Sao.common.message.run('Concurrency Exception',
|
||||
'tryton-warning').always(dfd.reject);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
Sao.common.error.run(data.error[0], data.error[1]);
|
||||
Sao.common.error.run(data.error[0], data.error[1])
|
||||
.always(dfd.reject);
|
||||
}
|
||||
dfd.reject();
|
||||
} else {
|
||||
result = data.result;
|
||||
if (session.cache) {
|
||||
@@ -119,16 +120,20 @@
|
||||
if (query.status == 401) {
|
||||
//Try to relog
|
||||
Sao.Session.renew(session).then(function() {
|
||||
Sao.rpc(args, session).then(dfd.resolve, dfd.reject);
|
||||
if (async) {
|
||||
Sao.rpc(args, session).then(dfd.resolve, dfd.reject);
|
||||
} else {
|
||||
dfd.resolve();
|
||||
}
|
||||
}, dfd.reject);
|
||||
return;
|
||||
} else if (query.status == 429) {
|
||||
Sao.common.message.run(
|
||||
Sao.i18n.gettext('Too many requests. Try again later.'),
|
||||
'tryton-error').always(dfd.reject);
|
||||
'tryton-error')
|
||||
.always(dfd.reject);
|
||||
} else {
|
||||
Sao.common.error.run(status_, error);
|
||||
dfd.reject();
|
||||
Sao.common.error.run(status_, error)
|
||||
.always(dfd.reject);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -154,6 +159,8 @@
|
||||
});
|
||||
if (async) {
|
||||
return dfd.promise();
|
||||
} else if (result === undefined) {
|
||||
throw dfd;
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user