kahmali / meteor-restivus

REST APIs for the Best of Us! - A Meteor 0.9+ package for building REST APIs https://atmospherejs.com/nimble/restivus
MIT License
544 stars 116 forks source link

User friendly error when passing invalid JSON #113

Open pvmeijel opened 9 years ago

pvmeijel commented 9 years ago

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

kahmali commented 9 years ago

I'll look into this when I return from vacation.

marcoeg commented 8 years ago

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.

dcantatore commented 7 years ago

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> &nbsp; &nbsp;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> &nbsp; &nbsp;at Object.parse (native)
<br> &nbsp; &nbsp;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.

Jexah commented 6 years ago

+1

anoop-chauhan commented 2 years ago

Hi, is anyone found any workaround for this issue?