Open
Description
sms(callback, phoneNumber, optionalParams=null) {
var params = {
phone_number: phoneNumber,
};
if (optionalParams !== null) {
params = Object.assign(params, optionalParams)
}
this.rest.execute(callback, "POST", this.smsResource, params);
}
the function sms in verify call rest client execute
execute(callback, methodName, resource, params = null) {
var telesignURL = this.restEndpoint + resource;
var bodyData = this.contentType=="application/json" ? "{}" : null;
if (methodName == "POST" || methodName == "PUT") {
if (params != null && Object.keys(params).length > 0) {
if (this.contentType == "application/x-www-form-urlencoded") {
bodyData = querystring.stringify(params);
} else {
bodyData = JSON.stringify(params);
}
}
}
else { // GET method
if (params != null) {
telesignURL = URI(this.restEndpoint + resource).query(params).toString();
}
else {
telesignURL = URI(this.restEndpoint + resource).toString();
}
}
var headers = RestClient.generateTeleSignHeaders(this.customerId,
this.apiKey,
methodName,
resource,
this.contentType,
bodyData,
null,
null,
this.userAgent);
var requestParams = {
headers: headers,
uri: telesignURL,
method: methodName,
timeout: this.timeout
};
if (bodyData != null) {
requestParams.body = bodyData;
}
request(requestParams, function (err, res, bodyStr) {
if (err) {
console.error(`FATAL ERROR: ${new Date()}`
+ ` Problems contacting Telesign Servers. Check your internet connection.`);
if (callback){
callback(err, bodyStr);
}
}
if (res) {
var body = JSON.parse(bodyStr); // HERE
if (callback){
callback(err, body);
}
}
});
}
}
where bodyStre being parse should be put in try catch
Metadata
Metadata
Assignees
Labels
No labels

Activity
kwanLeeFrmVi commentedon Mar 8, 2024
P/s: this could happen when I init class Telesign with in-correct restEndpoint arg
aidanatwork commentedon Mar 11, 2024
Hi @quanle1996 , I'm on the Product team here at Telesign, and would love to learn more about the issue you are raising here. I'm not sure I understand fully yet though. Could you explain to me further what you are seeing and what is the behavior you would expect to see instead? Thanks!
kwanLeeFrmVi commentedon Mar 12, 2024
Hi @aidanatwork,
I accidentally set restEndpoint = 'https://rest-api.telesign.com'
instead of 'https://rest-ww.telesign.com/v1'
in
this causes an un-catch exception at runtime.
this should be catch at
node_modules/telesignsdk/src/RestClient.jsrow :185as following
because bodyStr could be an invalid json so JSON.parse would throw error
aidanatwork commentedon Mar 12, 2024
Thanks @kwanLeeFrmVi , I'll report this to our SDK team.