- Hands-On Chatbot Development with Alexa Skills and Amazon Lex
- Sam Williams
- 298字
- 2021-07-16 17:45:08
External APIs
Every time you deal with anything outside of your code, there is a risk that it will error. This might be a third-party API, your own API, or simply a query to a database. You should always write these requests so that if the request returns an error, you fully deal with it. This means logging what the error was and where it took place and making sure that the chatbot still works when an error occurs.
Making sure that the chatbot still works when an error occurs is really important as no one wants to talk to a chatbot that just stops talking to you halfway through the conversation. To make sure this doesn't happen, you have three options: create error messages for every external call you make, let all errors flow down to a very low-level error handler that sends a generic We had an error message, or a combination of the two. The idea would be using custom messages for every error that could happen but as your chatbot becomes larger and more complicated, that can become very time-consuming.
An effective method for dealing with the errors is to create a low-level error handler that passes a generic error message unless a specific error message is provided. This gives you the flexibility to let the user know exactly what went wrong when it matters but saves you having to create lots of similar error messages:
try {
let result = AccessPeopleAPI();
if (result === null || typeof result !== 'number'){
throw 'I've failed to get the number of people';
}
return 'We have ' + result + ' people in the building';
} catch (error) {
console.log(error || 'The system has had an error');
return error || "Unfortunately I've had an error";
}
- EJB 3.1從入門到精通
- TCP/IP入門經(jīng)典(第5版)
- 通信簡史:從信鴿到6G+
- 網(wǎng)絡的琴弦:玩轉IP看監(jiān)控
- 中小型局域網(wǎng)組建、管理與維護實戰(zhàn)
- 計算機網(wǎng)絡與通信(第2版)
- Windows Server 2012 Hyper-V虛擬化管理實踐
- 4G小基站系統(tǒng)原理、組網(wǎng)及應用
- jQuery Mobile Web Development Essentials
- 網(wǎng)絡安全之道
- Cisco無線局域網(wǎng)配置基礎
- Corona SDK Application Design
- 網(wǎng)絡空間作戰(zhàn):機理與籌劃
- 物聯(lián)網(wǎng)商業(yè)設計與案例
- 加密與解密實戰(zhàn)全攻略