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

Posting malformed JSON throws an error #241

Open iMagdy opened 8 years ago

iMagdy commented 8 years ago

Hi, Im building a server-side API and when I POST a malformed JSON payload the app crashes:

SyntaxError: Unexpected token l
    at Object.parse (native)
    at parse (/home/islam/dist/app/programs/server/npm/node_modules/meteor/simple_json-routes/node_modules/connect/node_modules/body-parser/lib/types/json.js:88:17)
    at /home/islam/dist/app/programs/server/npm/node_modules/meteor/simple_json-routes/node_modules/connect/node_modules/body-parser/lib/read.js:108:18
    at invokeCallback (/home/islam/dist/app/programs/server/npm/node_modules/meteor/simple_json-routes/node_modules/connect/node_modules/body-parser/node_modules/raw-body/index.js:262:16)
    at done (/home/islam/dist/app/programs/server/npm/node_modules/meteor/simple_json-routes/node_modules/connect/node_modules/body-parser/node_modules/raw-body/index.js:251:7)
    at IncomingMessage.onEnd (/home/islam/dist/app/programs/server/npm/node_modules/meteor/simple_json-routes/node_modules/connect/node_modules/body-parser/node_modules/raw-body/index.js:308:7)
    at emitNone (events.js:67:13)
    at IncomingMessage.emit (events.js:166:7)
    at endReadableNT (_stream_readable.js:921:12)
    at nextTickCallbackWith2Args (node.js:442:9)

Did I miss something in the configuration ?

Jexah commented 7 years ago

This should be able to be handled in implementation by passing optional parameters. It seems this has not been built though.

iMagdy commented 7 years ago

Yeah, it's been an issue for over a year now, first reply coming after a year.

I believe there should be some sort of a decent validation engine built into any API framework. That's maybe something to contribute.