Closed parteekcoder closed 1 year ago
@parteekcoder Kindly check your JSON data you passed in body from Postman. It accepts whole data as a string ! console it and check what you have passed in body !
@parteekcoder Kindly check your JSON data you passed in body from Postman. It accepts whole data as a string ! console it and check what you have passed in body !
@codebloded yeah I have checked that But still is it failing
Give me a screenshot of body that you have passed in the request from postmam
I passed json as well as stringified data but both didn't work
I passed json as well as stringified data
This is good but I'm expecting the screenshot of body that you have passed from the postman! Are you using postman?
I passed json as well as stringified data
This is good but I'm expecting the screenshot of body that you have passed from the postman! Are you using postman?
@codebloded
Reproduce
- Start the server
- Make a request
The function where JSON.parse() is used having req object in the parse function, It will give following error
As this is useless , we don't need to use it here Because we are using
bodyParser
to convert req body
hey @llaske please see this error it is due to the JSON.parse() we are using
@llaske as we have used parsers here at https://github.com/llaske/sugarizer-server/blob/master/config/main.js#L33
There is no need to convert incoming data to JSON format here https://github.com/llaske/sugarizer-server/blob/master/api/controller/users.js#L432
So this line https://github.com/llaske/sugarizer-server/blob/master/api/controller/users.js#L432 produces error which I mentioned above
Refer here https://stackoverflow.com/questions/38380462/syntaxerror-unexpected-token-o-in-json-at-position-1
@llaske as we have used parsers here at https://github.com/llaske/sugarizer-server/blob/master/config/main.js#L33
There is no need to convert incoming data to JSON format here https://github.com/llaske/sugarizer-server/blob/master/api/controller/users.js#L432
So this line https://github.com/llaske/sugarizer-server/blob/master/api/controller/users.js#L432 produces error which I mentioned above
Refer here https://stackoverflow.com/questions/38380462/syntaxerror-unexpected-token-o-in-json-at-position-1
Yes, req.query
is automatically parsed and it's already being treated as a javascript object by addQuery
function.
However your postman request will still result in an error. JSON.parse(JSON.stringify(X))
should return the original object. If it is not returning the original object, then it means X
is not a JavaScript object.
Maybe you should consider stringifying your requests before sending them to the API endpoint.
@NikhilM98 is there any docs for sugarizer-server
Reproduce
The function where JSON.parse() is used having req object in the parse function, It will give following error
As this is useless , we don't need to use it here Because we are using
bodyParser
to convert req body