postalserver / postalserver/postal-node
JSON.parse Error when sending to a not working host
- Dominant language
- JavaScript
- Stars
- 70
- Forks
- 20
- PR merge metrics
- No merged PRs in 30d
Description
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 ()
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
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.