Skip to content

JSON.parse Error when sending to a not working host #3

@ramioooz

Description

@ramioooz

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions