added error handling to message sending

This commit is contained in:
Rohan Sircar 2019-11-22 20:25:08 +05:30
parent f95b14d4e9
commit 4b20c33ec1

View File

@ -235,7 +235,7 @@ function populateMessages(userName, passphrase) {
$(chatAreaNew).append(DOMPurify.sanitize(msgContainer));
})
scrollChatAreaAnimated(2400);
});
@ -301,6 +301,7 @@ document.getElementById('chatMessageForm').addEventListener('submit', function(e
let context = { fromUser: username, message: md.render(messageContent), time: new Date().toLocaleString() };
let msgContainer = msgContainerSendTemplate(context);
$(chatAreaNew).append(DOMPurify.sanitize(msgContainer));
scrollChatAreaAnimated(2400);
let messageCipher = sjcl.encrypt(passphraseInput.value, messageContent, { mode: "gcm", ts: 128, adata: "", iter: iterations });
let messageCipherJson = JSON.parse(messageCipher);
let chatMessageDTO = {
@ -326,7 +327,11 @@ function messageSend(chatMessageDTO) {
headers: headers,
body: chatMessageDTO
})
.then(response => console.log(response));
.then(response => {
console.log(response);
return response;
})
.then(response => fetchErrorHandler(response));
}
@ -411,4 +416,10 @@ function fetchErrorHandler(response) {
return true;
});
}
}
function scrollChatAreaAnimated(delay) {
$(chatAreaNew).stop().animate({
scrollTop: $(chatAreaNew)[0].scrollHeight
}, delay);
}