postal-node
postal-node copied to clipboard
JSON.parse Error when sending to a not working host
Hello developer,
I have a postal mail server working just fine I can send emails using your node js client with no problem.
now I turned my mail server off, I wanted to see if my application can candle such a scenario. but now I am getting an error related to your client. in my case it says something like :
SyntaxError: Unexpected token < in JSON at position 0
at JSON.parse (<anonymous>)
at D:\flutterProjects\project_01\node_modules\@atech\postal\Client.js:24:25
in the line 24 to 29 of Client.js I think instead of:
var json = JSON.parse(content);
if (json.status === 'success') {
resolve(json.data);
} else {
reject(json.data);
}
I think you should do something like this:
try {
var json = JSON.parse(content);
if (json.status === 'success') {
resolve(json.data);
} else {
reject(json.data);
}
} catch (error) {
// reject(error.toString());
var msg = 'cant parse response. please check your connection to the mail server';
reject(msg);
}
I hope this helps, Thank you
Raise a PR and I'm sure we'll get it merged!