Skip to content

handle undefined request body gracefully #15

Description

@stuikomma

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.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions