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:
JC Brand 2021-06-28 13:09:18 +02:00
parent 767d5ec91d
commit 956a890b94

View File

@ -665,8 +665,7 @@ const ChatRoomMixin = {
* @method _converse.ChatRoom#sendTimedMessage * @method _converse.ChatRoom#sendTimedMessage
* @param { _converse.Message|XMLElement } message * @param { _converse.Message|XMLElement } message
* @returns { Promise<XMLElement>|Promise<_converse.TimeoutError> } Returns a promise * @returns { Promise<XMLElement>|Promise<_converse.TimeoutError> } Returns a promise
* which resolves with the reflected message stanza or rejects * which resolves with the reflected message stanza or with an error stanza or {@link _converse.TimeoutError}.
* with an error stanza or with a {@link _converse.TimeoutError}.
*/ */
sendTimedMessage (el) { sendTimedMessage (el) {
if (typeof el.tree === 'function') { if (typeof el.tree === 'function') {
@ -678,28 +677,18 @@ const ChatRoomMixin = {
id = this.getUniqueId('sendIQ'); id = this.getUniqueId('sendIQ');
el.setAttribute('id', id); el.setAttribute('id', id);
} }
let handler; const promise = getOpenPromise();
const timeoutHandler = _converse.connection.addTimedHandler(_converse.STANZA_TIMEOUT, () => { const timeoutHandler = _converse.connection.addTimedHandler(_converse.STANZA_TIMEOUT, () => {
_converse.connection.deleteHandler(handler); _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; return false;
}); });
const promise = new Promise((resolve, reject) => { const handler = _converse.connection.addHandler(
handler = _converse.connection.addHandler( stanza => {
stanza => { timeoutHandler && _converse.connection.deleteTimedHandler(timeoutHandler);
timeoutHandler && _converse.connection.deleteTimedHandler(timeoutHandler); promise.resolve(stanza);
if (stanza.getAttribute('type') === 'groupchat') { }, null, 'message', ['error', 'groupchat'], id);
resolve(stanza);
} else {
reject(stanza);
}
},
null,
'message',
['error', 'groupchat'],
id
);
});
api.send(el); api.send(el);
return promise; return promise;
}, },
@ -737,10 +726,12 @@ const ChatRoomMixin = {
'retraction_id': stanza.nodeTree.getAttribute('id'), 'retraction_id': stanza.nodeTree.getAttribute('id'),
'editable': false 'editable': false
}); });
try { const result = await this.sendTimedMessage(stanza);
await this.sendTimedMessage(stanza);
} catch (e) { if (u.isErrorStanza(result)) {
log.error(e); log.error(result);
} else if (result instanceof _converse.TimeoutError) {
log.error(result);
message.save({ message.save({
editable, editable,
'error_type': 'timeout', 'error_type': 'timeout',