sails.js: call 404 manually
http-status-code-404, javascript, node.js, sails.js
Solution
`res.notFound()` should do the trick for version 0.10.
Have a look at your `api/responses/` folder, it contains the default error response helpers for sails and allows you to come up with your own response types by saving files there.
Included by default:
/api/responses
badRequest.js - 400 - res.badRequest()
notFound.js - 404 - res.notFound()
forbidden.js - 403 - res.forbidden()
serverError.js - 500 - res.serverError()
Roll your own:
/api/responses
notAcceptable.js - res.notAcceptable();
Example (modified api/responses/notFound.js):
module.exports = function notAcceptable() {
var req = this.req;
var res = this.res;
var viewFilePath = 405;
var statusCode = 405;
var result = {
status: statusCode
};
if (req.wantsJSON) {
return res.json(result, result.status);
}
res.status(result.status);
res.render(viewFilePath, function(err) {
if (err) {
return res.json(result, result.status);
}
res.render(viewFilePath);
});
};
Problem
I'm looking for a way to use the default 404 error provided by sails.js framework. The doc is here http://sailsjs.org/#!documentation/config.404 but I'm wondering how I can call the 404 method from another controller. Of course I could use the code in the doc, but I would have prefered to use the dedicated framework method.