Open pvmeijel opened 9 years ago
I'll look into this when I return from vacation.
I would be interested too in a better way to catch payloads with not well formed JSON objects. Could this be handled by middleware ? Thank you for your reply and the great package.
I'm also having this issue with clients able to send invalid formatted JSON. How can we catch this and respond with an error?
post:
abc
Response:
Error: invalid json
<br> at parse (/home/ubuntu/.meteor/packages/simple_json-routes/.2.1.0.12bfasl++os+web.browser+web.cordova/npm/node_modules/connect/node_modules/body-parser/lib/types/json.js:83:15)
Then many more lines of error
if they post with invalid object:
{"name": aaa}
response:
SyntaxError: Unexpected token a
<br> at Object.parse (native)
<br> at parse (/home/ubuntu/.meteor/packages/simple_json-routes/.2.1.0.12bfasl++os+web.browser+web.cordova/npm/node_modules/connect/node_modules/body-parser/lib/types/json.js:88:17)
It seems like the simple_json-routes is handling this first before I can even do type checks, obj field checks, etc.
How can we handle this? It doesn't look very good or help the person that doesn't know how to fully use the API.
+1
Hi, is anyone found any workaround for this issue?
Hello,
When a user passes invalid JSON data, Restivus responds with a stack trace like "SyntaxError: Unexpected string etc etc". Is it possible to catch the error and give a more user friendly response in such situations?
Regards, Peter