express-debug icon indicating copy to clipboard operation
express-debug copied to clipboard

handle undefined request body gracefully

Open stuikomma opened this issue 10 years ago • 0 comments

I'm getting the exception:

TypeError: Object.keys called on non-object at Function.keys (native) at Object.request.add ([...]\node_modules\express-debug\lib\request.js:11:33) at ServerResponse.send ([...]\node_modules\express-debug\lib\response.js:122:21) at module.exports ([...]\routes\share.js:10:23) at Layer.handle as handle_request at next ([...]\node_modules\express\lib\router\route.js:110:13) at Route.dispatch ([...]\node_modules\express\lib\router\route.js:91:3) at Layer.handle as handle_request at [...]\node_modules\express\lib\router\index.js:267:22 at Function.proto.process_params ([...]\node_modules\express\lib\router\index.js:321:12) at next ([...]\node_modules\express\lib\router\index.js:261:10) at checkSession ([...]\src\server\urlSessions.js:48:14) at module.exports.middleware ([...]\src\server\urlSessions.js:21:14) at Layer.handle as handle_request at trim_prefix ([...]\node_modules\express\lib\router\index.js:302:13) at [...]\node_modules\express\lib\router\index.js:270:7 at Function.proto.process_params ([...]\node_modules\express\lib\router\index.js:321:12) at next ([...]\node_modules\express\lib\router\index.js:261:10) at cookieParser ([...]\node_modules\cookie-parser\index.js:48:5) at Layer.handle as handle_request at trim_prefix ([...]\node_modules\express\lib\router\index.js:302:13) at [...]\node_modules\express\lib\router\index.js:270:7 at Function.proto.process_params ([...]\node_modules\express\lib\router\index.js:321:12) at next ([...]\node_modules\express\lib\router\index.js:261:10) at logger ([...]\node_modules\morgan\index.js:136:5) at Layer.handle as handle_request at trim_prefix ([...]\node_modules\express\lib\router\index.js:302:13) at [...]\node_modules\express\lib\router\index.js:270:7 at Function.proto.process_params ([...]\node_modules\express\lib\router\index.js:321:12) at next ([...]\node_modules\express\lib\router\index.js:261:10) at SendStream.error ([...]\node_modules\express\node_modules\serve-static\index.js:106:7) at SendStream.emit (events.js:95:17) at SendStream.error ([...]\node_modules\express\node_modules\send\index.js:244:17) at SendStream.onStatError ([...]\node_modules\express\node_modules\send\index.js:340:48) at next ([...]\node_modules\express\node_modules\send\index.js:591:16) at onstat ([...]\node_modules\express\node_modules\send\index.js:580:14) at Object.oncomplete (fs.js:107:15)

This happens because req.body is undefined in request.js:11. Writing req.body !== undefined ? Object.keys(req.body).length ? req.body : req.rawBody : req.rawBody, solves this.

stuikomma avatar Jan 15 '15 10:01 stuikomma