Provide better errors when content length is incorrect #894

gdbtek opened this Issue Sep 13, 2013 · 1 comment


None yet
2 participants

gdbtek commented Sep 13, 2013

if a client sends a request with content-length is incorrect (Ex: length less than the actual length), connect will throw runtime errors like this but good thing is it does not crash server:

Express server listening on port 3000
SyntaxError: Unexpected end of input
    at Object.parse (native)
    at IncomingMessage.<anonymous> (/Volumes/Data/Junk/myapp/node_modules/express/node_modules/connect/lib/middleware/json.js:76:27)
    at IncomingMessage.EventEmitter.emit (events.js:92:17)
    at _stream_readable.js:920:16
    at process._tickCallback (node.js:415:13)
POST /users 400 7ms

Expected: would be great that connect can provide better errors, like throw back error object or something like that.

@jonathanong for your review. Thanks


jonathanong commented Oct 17, 2013

okay so i don't think this is possible via connect because the error occurs at JSON.parse. obviously we don't know if it's valid JSON unless we parse it. i guess you're just going to have to google it if you get this error. not sure how to improve it except by catching this specific error and renaming it, which i'm not going to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment