Edit Page

res.notFound()

This method is used to send a 404 ("Not Found") response using either res.json() or res.view(). It is called automatically when Sails receives a request that doesn't match any of its explicit routes or route blueprints (i.e. serves the 404 page).

When called manually from your app code, this method is normally used to indicate that the user agent tried to find, update, or delete something that doesn't exist.

Usage

#
return res.notFound();

Details

#

Like the other built-in custom response modules, the behavior of this method is customizable.

By default, it works as follows:

Example

#
Pet.findOne()
.where({ name: 'fido' })
.exec(function(err, fido) {
  if (err) return res.serverError(err);
  if (!fido) return res.notFound();
  // ...
})

Notes

#
  • This method is terminal, meaning that it is generally the last line of code your app should run for a given request (hence the advisory usage of return throughout these docs).
  • res.notFound() (like other userland response methods) can be overridden or modified. It runs the response method defined in api/responses/notFound.js. If a notFound.js response method does not exist in your app, Sails will use the default behavior.

Is something missing?

If you notice something we've missed or could be improved on, please follow this link and submit a pull request to the sails repo. Once we merge it, the changes will be reflected on the website the next time it is deployed.

Reference

Reference