Comments (10)
@graut I am getting no Sorry, duplicate contact found with the same email address. I got {"error":"Unexpected token S","stack":"SyntaxError: Unexpected token S\n and was wondering what is happening.
You guys should handle better errors. This part
var contacts = JSON.parse(body);
can always throw an error. can you change your code?
Maybe I am going to refactor your code.
from nodejs.
Hi Please use status code to check status is not 200 and do action based on that. For example please test with below code in ContactAPI.prototype.add function on success -
`ContactAPI.prototype.add = function add(contact, success, failure) {
var options = this.getOptions();
options.path = '/dev/api/contacts';
options.method = 'POST';
options.headers['Content-Type'] = 'application/json';
var post = https.request(options, function(resp) {
resp.setEncoding('utf8');
var body = "";
resp.on('data', function(data) {
body += data;
});
resp.on('end', function() {
if (success) {
try {
console.log(resp.statusCode);
var statusCode = resp.statusCode;
if (statusCode != 200){
console.log(body)
return;
}
var contacts = JSON.parse(body);
success(contacts);
} catch (ex) {
failure(ex);
}
}
});
resp.on('error', function(e) {
if (failure) {
failure(e);
}
});
});
try {
var data = JSON.stringify(contact);
post.write(data);
post.end();
} catch (ex) {
failure(ex);
}
};`
from nodejs.
What happened to duplicate email error? This time we don't get any error. It can create contacts with same email accounts twice.
from nodejs.
Hi @mete89
I am getting duplicate contact with same email address as you can see in below link image.
First time it is creating contact with unique email and second time we are checking email and if found then we throwing 400 status code with error message : duplicate contact
In Agile CRM unique email only allowed.
You can see my sample code which I tested and you can also check with your credential
In same folder
- agilecrm.js
https://gist.github.com/graut/8107a3213b8a50028dec1b692d98f983 - test.js
https://gist.github.com/graut/987c6223d8c2b0effce890c301190946
Please let me know if you need any further information.
Thanks
from nodejs.
Hi @ernho ,
Could you please let us know what is the status code printing for your request. Please check below agilecrm.js file with small modification which will catch 400 error and show duplicate error message.
We will update npm file for few method with error code and message. Please note that for 400 error code you can get proper message but for 500 server error as we are directly throwing error to user, Message won't we formatted and may be in the form of Java exception.
If you will pass correct format of JSON to Agile CRM then there is very rare chance of getting 500 server error.
Please let us know in case need further help.
Thanks
from nodejs.
Hi @graut
I am getting this error when I tried to insert a existing contact. Maybe it was not clear but you should catch the error thown by the parse function:
var contacts = JSON.parse(body);
JSON.parse() thows this {"error":"Unexpected token S","stack":"SyntaxError:.. error so this is not good
if (success) {
try {
var contacts = JSON.parse(body);
success(contacts);
} catch (ex) {
failure(ex);
}
}
In your modification when body is empty it will trow again the same error
from nodejs.
Hi @ernho,
Yes you are write. I will add some code for checking exception thrown by parse too.
Thank you for you suggestion. We will implement this changes very soon for exception handling in node.js files.
Meanwhile please add try catch for parse and our suggestion for error handling. You can add above changes to every method which are frequently used by your application.
Please let us know in case need further information.
from nodejs.
What is the current status about improved Error handling? I wasted a lot hours because the miss leading error messages. Also if your function receive success and error functions, errors should always be returned over the error and not the success function, which was not the case for me.
from nodejs.
Hi @tilman,
Could you please let me know which package version of npm (agile_crm) you are using ? In our latest code we have simple error handling to show status code and message. Some time while parsing empty data there are possibility of throwing exception and that is why we are also throwing exception from success code.
Since this code is sample for testing all methods, It is strongly recommended to modify your method as accordance to your requirement and use.
In case you need more information regarding Agile CRM REST API please check below main reference :
https://github.com/agilecrm/rest-api
from nodejs.
Hi all Please find the latest code we have updated error handling code, if you are facing any issues please let us know ,
In case you need more information regarding Agile CRM REST API please check below main reference :
https://github.com/agilecrm/rest-api
Thanks,
Agile crm support team.
from nodejs.
Related Issues (15)
- Is this going to be updated in npm website? HOT 7
- Missing error handling code HOT 1
- Fork with fixes
- make this library promise based?
- lacks a method to update lead score HOT 4
- updateTagsById is not a function HOT 2
- Is this project alive? HOT 2
- page_size parameter
- getContactByEmail throws exception if no contact found
- "deleteContact" returning error
- Event API? HOT 1
- Status Code Spam HOT 2
- HTTP400 on function getDealByContactId HOT 1
- NO License Information
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nodejs.