Skip to content

Commit

Permalink
Improve error handling
Browse files Browse the repository at this point in the history
`send()`ing an Error object just returns `{}`. Better to pass errors like this on to Express's default error handling.
  • Loading branch information
Dallon Feldner committed Aug 21, 2015
1 parent ca0ef0c commit 515e45c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ FalcorEndpoint.expressMiddleware = function(getDataSource) {
};

FalcorEndpoint.dataSourceRoute = function(getDataSource) {
return function(req, res) {
return function(req, res, next) {
var obs;
var dataSource = getDataSource(req, res);
var context = requestToContext(req);
Expand All @@ -34,8 +34,10 @@ FalcorEndpoint.dataSourceRoute = function(getDataSource) {
obs.subscribe(function(jsonGraphEnvelope) {
res.status(200).send(JSON.stringify(jsonGraphEnvelope));
}, function(err) {
if (err instanceof Error) {
return next(err);
}
res.status(500).send(err);
});
};
};

0 comments on commit 515e45c

Please sign in to comment.