feathers-plus / cli

FeathersJS CLI supporting both REST and GraphQL architectural concepts and their query languages.
https://generator.feathers-plus.com/
Other
43 stars 7 forks source link

Mongoose.connect miss catch error statment #14

Closed MartinBucko closed 6 years ago

MartinBucko commented 6 years ago

Steps to reproduce

I ship my app first time to production server and accidentally setup bad mongodb config URL. In logs it don't show nothing only message Unhandled Rejection at: Promise ... It was hard to find the problem in bad password setup in mongodb URL. After this i found mongoose.connect don't have catch statement.

Expected behavior

mongose.connect should throw error after connection fail

In generated file from cli src/mongoose.js should be:

mongoose
    .connect(app.get('mongodb'), {})
    .catch(err => {
      console.error('Mongoose connection error: ', err)
    })

Module versions (especially the part that's not working):

feathers-plus cli version 0.4.23

eddyystop commented 6 years ago

Thank you.

eddyystop commented 6 years ago

A basic goal of the generator is to remain source compatible with feathersjs.cli, which does not log such connection failures.

I've asked around and found that some people do modify this particular feathersjs/cli code. I'm proposing the code be changed to:

  mongoose.Promise = global.Promise
  mongoose.connect(app.get('mongodb'), {})
  .then(({ connection }) => {
    console.log(`connected to "${connection.name}" database at ${connection.host}:${connection.port}`)
    return connection
  })
  .catch(error => {
    console.log(error)
    process.exit(0)
  })

  app.set('mongooseClient', mongoose)

Comments?

eddyystop commented 6 years ago

The TS version needs

.then(({ connection }: any) => {
eddyystop commented 6 years ago

Published in @feathers-plus/cli v0.4.24 using generator v0.2.30.