Skip to content
Snippets Groups Projects
Commit df652c5c authored by Dominic Krämer's avatar Dominic Krämer
Browse files

add exceptions for failed connection

parent 47748008
No related branches found
No related tags found
No related merge requests found
......@@ -14,9 +14,14 @@ def home():
def sendmessage():
message = request.form['message']
print(message)
rasa_response = requests.post('http://localhost:5005/webhooks/rest/webhook', json={"message": message})
responses = []
try:
rasa_response = requests.post('http://localhost:5005/webhooks/rest/webhook', json={"message": message})
except Exception as e:
print(f"error: {e}")
responses.append({"type": "text", "content": "Oh, it appears that I'm not availabe. Please try again later!"})
return jsonify(responses)
for resp in rasa_response.json():
if "text" in resp:
responses.append({"type": "text", "content": resp["text"]})
......
......@@ -34,6 +34,17 @@ function sendMessage() {
chat.insertBefore(newDiv, chat.firstChild);
// document.getElementById("chat").appendChild(newDiv);
})
.catch((error) => {
console.error(error);
let newDiv = document.createElement("div");
newDiv.className = "message-bot";
let newP = document.createElement("p");
newP.textContent = "Oh, it appears that I'm not availabe. Please check your internet connection!";
newDiv.appendChild(newP);
let chat = document.getElementById("chat");
chat.insertBefore(newDiv, chat.firstChild);
});
}
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment