Skip to content

UnhandledPromiseRejectionWarning thrown when content-type is not sent #94

@v3rse

Description

@v3rse

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'
  1. Run it using micro-dev
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions