Skip to content

Commit 92a4c26

Browse files
Steve Greengermanattanasio
authored andcommitted
fix: Added server errors to be displayed in the chat area (#222)
* Show server error such as session timeout in chat window * Enforced node >=8.15.0 to resolve 502 errors with node 6.15.0 * Added 1 second pause before scrolling chat window to fix image loading in chat window
1 parent ec13fd8 commit 92a4c26

4 files changed

Lines changed: 28 additions & 4 deletions

File tree

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
"registry": "https://registry.npmjs.org/",
2929
"access": "public"
3030
},
31+
"engines": {
32+
"node": ">=8.15.0"
33+
},
34+
"engineStrict": true,
3135
"devDependencies": {
3236
"babel-eslint": "^8.2.6",
3337
"casperjs": "^1.1.4",

public/js/api.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ var Api = (function() {
2727
},
2828
setResponsePayload: function(newPayloadStr) {
2929
responsePayload = JSON.parse(newPayloadStr);
30+
},
31+
setErrorPayload: function() {
3032
}
3133
};
3234

@@ -35,7 +37,7 @@ var Api = (function() {
3537
http.open('GET', sessionEndpoint, true);
3638
http.setRequestHeader('Content-type', 'application/json');
3739
http.onreadystatechange = function () {
38-
if (http.readyState == XMLHttpRequest.DONE) {
40+
if (http.readyState === XMLHttpRequest.DONE) {
3941
var res = JSON.parse(http.responseText);
4042
sessionId = res.session_id;
4143
callback();
@@ -65,8 +67,19 @@ var Api = (function() {
6567
http.open('POST', messageEndpoint, true);
6668
http.setRequestHeader('Content-type', 'application/json');
6769
http.onreadystatechange = function() {
68-
if (http.readyState === 4 && http.status === 200 && http.responseText) {
70+
if (http.readyState === XMLHttpRequest.DONE && http.status === 200 && http.responseText) {
6971
Api.setResponsePayload(http.responseText);
72+
} else if (http.readyState === XMLHttpRequest.DONE && http.status !== 200) {
73+
Api.setErrorPayload({
74+
'output': {
75+
'generic': [
76+
{
77+
'response_type': 'text',
78+
'text': 'I\'m having trouble connecting to the server, please refresh the page'
79+
}
80+
],
81+
}
82+
});
7083
}
7184
};
7285

public/js/conversation.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ var ConversationPanel = (function () {
4646
currentResponsePayloadSetter.call(Api, newPayloadStr);
4747
displayMessage(JSON.parse(newPayloadStr), settings.authorTypes.watson);
4848
};
49+
50+
Api.setErrorPayload = function (newPayload) {
51+
displayMessage(newPayload, settings.authorTypes.watson);
52+
};
4953
}
5054

5155
// Set up the input box to underline text as it is typed
@@ -146,7 +150,10 @@ var ConversationPanel = (function () {
146150
// Class to start fade in animation
147151
currentDiv.classList.add('load');
148152
// Move chat to the most recent messages when new messages are added
149-
scrollToChatBottom();
153+
setTimeout(function () {
154+
// wait a sec before scrolling
155+
scrollToChatBottom();
156+
}, 1000);
150157
setResponse(responses, isUser, chatBoxElement, index + 1, false);
151158
} else {
152159
var userTypringField = document.getElementById('user-typing-field');

0 commit comments

Comments
 (0)