llaske / sugarizer-server

Sugarizer Server allow deployment of Sugarizer on a local server, for example on a school server.
Apache License 2.0
43 stars 94 forks source link

Error while requesting #371

Closed parteekcoder closed 1 year ago

parteekcoder commented 1 year ago

Reproduce

  1. Start the server
  2. Make a request

The function where JSON.parse() is used having req object in the parse function, It will give following error

image

As this is useless , we don't need to use it here Because we are using bodyParser to convert req body

codebloded commented 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 commented 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 !

@codebloded yeah I have checked that But still is it failing

codebloded commented 1 year ago

Give me a screenshot of body that you have passed in the request from postmam

parteekcoder commented 1 year ago

image

I passed json as well as stringified data but both didn't work

codebloded commented 1 year ago

image

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?

parteekcoder commented 1 year ago

image 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?

image

@codebloded

parteekcoder commented 1 year ago

Reproduce

  1. Start the server
  2. Make a request

The function where JSON.parse() is used having req object in the parse function, It will give following error

image

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

parteekcoder commented 1 year ago

@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

parteekcoder commented 1 year ago

@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

NikhilM98 commented 1 year ago

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.

parteekcoder commented 1 year ago

@NikhilM98 is there any docs for sugarizer-server

NikhilM98 commented 1 year ago