fojas / cleverbot-node

Cleverbot client in node.js
MIT License
62 stars 33 forks source link

Error handling #38

Closed kohltastrophe closed 7 years ago

kohltastrophe commented 7 years ago

In cleverbot.js you have an issue on line 58 where the eval will error without catching it, halting the program.

This can be fixed by changing line 58 from: eval("responseBody = " + body) to: try {eval("responseBody = " + body)} catch(e) {console.log(e)}

AND changing line 60-61 from:

responseBody.message = responseBody.output;
this.state = responseBody.cs;

to:

try {
responseBody.message = responseBody.output;
this.state = responseBody.cs;
} catch(e) {console.log(e)}

Thanks for the great package otherwise!

fojas commented 7 years ago

I added an errorCallback argument to the write function. I don't want to make assumptions about how users want to handle errors. If an error occurs, the callback is called and the write function just returns without continuing. I hope that is enough.

Thanks!

kohltastrophe commented 7 years ago

Even better than my temporary fix, keep up the good work!