Merge pull request #70 from strongloop/feature/return-standard-error-for-unkown-url

Add loopback.urlNotFound() middleware.
This commit is contained in:
Miroslav Bajtoš 2013-11-19 11:39:28 -08:00
commit e3a15ccb38
1 changed files with 18 additions and 0 deletions

View File

@ -0,0 +1,18 @@
/**
* Export the middleware.
*/
module.exports = urlNotFound;
/**
* Convert any request not handled so far to a 404 error
* to be handled by error-handling middleware.
* See discussion in Connect pull request #954 for more details
* https://github.com/senchalabs/connect/pull/954
*/
function urlNotFound() {
return function raiseUrlNotFoundError(req, res, next) {
var error = new Error('Cannot ' + req.method + ' ' + req.url);
error.status = 404;
next(error);
}
}