vercel / micro-dev

The development environment for `micro`
MIT License
705 stars 77 forks source link

UnhandledPromiseRejectionWarning thrown when content-type is not sent #94

Open v3rse opened 5 years ago

v3rse commented 5 years ago

Issue summary

micro-dev throws the following:

(node:29516) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'indexOf' of undefined
    at logRequest (/home/v3rse/TheFactory/code/learn/javascript/playground/frameworks/micro/hello-micro/node_modules/micro-dev/lib/log.js:38:71)
    at initLog (/home/v3rse/TheFactory/code/learn/javascript/playground/frameworks/micro/hello-micro/node_modules/micro-dev/lib/log.js:97:23)
    at /home/v3rse/TheFactory/code/learn/javascript/playground/frameworks/micro/hello-micro/node_modules/micro-dev/lib/log.js:123:2
    at resolve (/home/v3rse/TheFactory/code/learn/javascript/playground/frameworks/micro/hello-micro/node_modules/micro/lib/index.js:96:33)
    at new Promise (<anonymous>)
    at Function.exports.run (/home/v3rse/TheFactory/code/learn/javascript/playground/frameworks/micro/hello-micro/node_modules/micro/lib/index.js:96:2)
    at Server.server (/home/v3rse/TheFactory/code/learn/javascript/playground/frameworks/micro/hello-micro/node_modules/micro/lib/index.js:13:50)
    at emitTwo (events.js:126:13)
    at Server.emit (events.js:214:7)
    at parserOnIncoming (_http_server.js:656:12)
(node:29516) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
(node:29516) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 2)

From what I can tell this happens on the following line when a content-type is not sent in the header: https://github.com/zeit/micro-dev/blob/7ea8ae05a56fa76788bed6fc9ee2d38728e0eac6/lib/log.js#L38

How to reproduced:

  1. Set a simple micro project
    module.exports = () => 'Hello'
  2. Run it using micro-dev
  3. Send the following to localhost:3000 without setting a content-type header
    
    POST http://localhost:3000/

{ "test": "some-data" }



You should see the above error in your console
v3rse commented 5 years ago

Will push a PR for this soon