tommybananas / finale

Create flexible REST endpoints and controllers from Sequelize models in your Express app
187 stars 36 forks source link

Pass unhandled errors back to Express #11

Closed jorrit closed 6 years ago

jorrit commented 6 years ago

I would like to request that certain errors are passed back to Express so they may be handled by route handlers later. This relates to the following code in base.js:

  hookChain
    .catch(errors.RequestCompleted, _.noop)
    .catch(self.model.sequelize.ValidationError, function(err) {
      var errorList = _.reduce(err.errors, function(result, error) {
        result.push({ field: error.path, message: error.message });
        return result;
      }, []);

      self.error(req, res, new errors.BadRequestError(err.message, errorList, err));
    })
    .catch(errors.FinaleError, function(err) {
      self.error(req, res, err);
    })
    .catch(function(err) {
      self.error(req, res, new errors.FinaleError(500, 'internal error', [err.message], err));
    });

The last catch statement seems to concern all unexpected errors which I would like to handle in Express for logging purposes.

The change seems to be quite simple, I just would like to know if the maintainer is willing to consider such a change. If so, I will make a PR.

tommybananas commented 6 years ago

Yep go for it, thanks

On Mon, Mar 12, 2018 at 9:39 AM Jorrit Schippers notifications@github.com wrote:

I would like to request that certain errors are passed back to Express so they may be handled by route handlers later. This relates to the following code in base.js:

hookChain .catch(errors.RequestCompleted, .noop) .catch(self.model.sequelize.ValidationError, function(err) { var errorList = .reduce(err.errors, function(result, error) { result.push({ field: error.path, message: error.message }); return result; }, []);

  self.error(req, res, new errors.BadRequestError(err.message, errorList, err));
})
.catch(errors.FinaleError, function(err) {
  self.error(req, res, err);
})
.catch(function(err) {
  self.error(req, res, new errors.FinaleError(500, 'internal error', [err.message], err));
});

The last catch statement seems to concern all unexpected errors which I would like to handle in Express for logging purposes.

The change seems to be quite simple, I just would like to know if the maintainer is willing to consider such a change. If so, I will make a PR.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/tommybananas/finale/issues/11, or mute the thread https://github.com/notifications/unsubscribe-auth/ACELEx9awvVz78KkvdwLQRwxAzVn53Yrks5tdoiggaJpZM4SmwjN .