Don't reject on error in sendTimedMessage
It's the only way I could get a failing test (due to the Jasmine upgrade AFAIK) to pass. I don't understand why this happens, given that the promise has a `catch` clause in `retractOwnMessage`, but for some reason the promise rejection gets caught by Jasmine, causing the test to fail.
This commit is contained in:
parent
767d5ec91d
commit
956a890b94
|
@ -665,8 +665,7 @@ const ChatRoomMixin = {
|
|||
* @method _converse.ChatRoom#sendTimedMessage
|
||||
* @param { _converse.Message|XMLElement } message
|
||||
* @returns { Promise<XMLElement>|Promise<_converse.TimeoutError> } Returns a promise
|
||||
* which resolves with the reflected message stanza or rejects
|
||||
* with an error stanza or with a {@link _converse.TimeoutError}.
|
||||
* which resolves with the reflected message stanza or with an error stanza or {@link _converse.TimeoutError}.
|
||||
*/
|
||||
sendTimedMessage (el) {
|
||||
if (typeof el.tree === 'function') {
|
||||
|
@ -678,28 +677,18 @@ const ChatRoomMixin = {
|
|||
id = this.getUniqueId('sendIQ');
|
||||
el.setAttribute('id', id);
|
||||
}
|
||||
let handler;
|
||||
const promise = getOpenPromise();
|
||||
const timeoutHandler = _converse.connection.addTimedHandler(_converse.STANZA_TIMEOUT, () => {
|
||||
_converse.connection.deleteHandler(handler);
|
||||
promise.reject(new _converse.TimeoutError('Timeout Error: No response from server'));
|
||||
const err = new _converse.TimeoutError('Timeout Error: No response from server');
|
||||
promise.resolve(err);
|
||||
return false;
|
||||
});
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
handler = _converse.connection.addHandler(
|
||||
stanza => {
|
||||
timeoutHandler && _converse.connection.deleteTimedHandler(timeoutHandler);
|
||||
if (stanza.getAttribute('type') === 'groupchat') {
|
||||
resolve(stanza);
|
||||
} else {
|
||||
reject(stanza);
|
||||
}
|
||||
},
|
||||
null,
|
||||
'message',
|
||||
['error', 'groupchat'],
|
||||
id
|
||||
);
|
||||
});
|
||||
const handler = _converse.connection.addHandler(
|
||||
stanza => {
|
||||
timeoutHandler && _converse.connection.deleteTimedHandler(timeoutHandler);
|
||||
promise.resolve(stanza);
|
||||
}, null, 'message', ['error', 'groupchat'], id);
|
||||
api.send(el);
|
||||
return promise;
|
||||
},
|
||||
|
@ -737,10 +726,12 @@ const ChatRoomMixin = {
|
|||
'retraction_id': stanza.nodeTree.getAttribute('id'),
|
||||
'editable': false
|
||||
});
|
||||
try {
|
||||
await this.sendTimedMessage(stanza);
|
||||
} catch (e) {
|
||||
log.error(e);
|
||||
const result = await this.sendTimedMessage(stanza);
|
||||
|
||||
if (u.isErrorStanza(result)) {
|
||||
log.error(result);
|
||||
} else if (result instanceof _converse.TimeoutError) {
|
||||
log.error(result);
|
||||
message.save({
|
||||
editable,
|
||||
'error_type': 'timeout',
|
||||
|
|
Reference in New Issue