Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handler should reject not throw #61

Closed
daffl opened this issue Feb 23, 2016 · 2 comments
Closed

Error handler should reject not throw #61

daffl opened this issue Feb 23, 2016 · 2 comments

Comments

@daffl
Copy link
Member

daffl commented Feb 23, 2016

The current error handler re-throws the new error which will simply crash and exit the server. Can be reproduced by POSTing something that doesn't match the schema to /users in an app like this:

const feathers = require('feathers');
const rest = require('feathers-rest');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const mongooseService = require('feathers-mongoose');
const errors = require('feathers-errors');

mongoose.connect('mongodb://localhost:27017/testing');

const app = feathers()
  .configure(rest())
  .use(bodyParser.json())
  .use(bodyParser.urlencoded({ extended: true }));

const Schema = mongoose.Schema;
const MessageSchema = new Schema({
  text: {
    type: String,
    required: true
  },
  read: {
    type: Boolean,
    'default': false
  }
});
const Model = mongoose.model('Message', MessageSchema);

app.use('users', mongooseService({ Model }));
app.use(errors.handler({ html: false }));

app.listen(3000, () => {
  console.log('hey');
});

The fix is in https://github.com/feathersjs/feathers-mongoose/blob/master/src/error-handler.js#L24 to run

return Promise.reject(feathersError);

instead of throwing it.

@daffl
Copy link
Member Author

daffl commented Feb 23, 2016

Actually, this happens only when not setting

// Make Mongoose use the ES6 promise
mongoose.Promise = global.Promise;

Although it is documented, since it is an easy to make and hard to debug mistake I will create a PR with the suggested fix and also highlight using the global.Promise in the documentation.

@ekryski
Copy link
Member

ekryski commented Feb 23, 2016

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants