-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Denormalize response code by removing `build-outlet-function` factory. This just makes the response code clearer. * No more use of `jsonx` -- when `res.json()` is used, errors are turned into stack traces first unless they have a `.toJSON()` * Only `badRequest` and `serverError` can send output * No more view guessing / second arguments * Default 500 handler uses `serverError` instead of `negotiate`
- Loading branch information
Showing
8 changed files
with
203 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
* Module dependencies | ||
*/ | ||
|
||
var buildOutletFunction = require('../helpers/build-outlet-function'); | ||
var _ = require('@sailshq/lodash'); | ||
|
||
|
||
|
||
|
@@ -25,17 +25,41 @@ var buildOutletFunction = require('../helpers/build-outlet-function'); | |
* automatically. | ||
*/ | ||
|
||
module.exports = function notFound (data, options) { | ||
module.exports = function notFound (data) { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
var config = { | ||
logMessage: 'Sending 404 ("Not Found") response', | ||
statusCode: 404, | ||
logData: true, | ||
isError: true, | ||
isGuessView: false, | ||
name: 'notFound' | ||
}; | ||
// Get access to `req` and `res` | ||
var req = this.req; | ||
var res = this.res; | ||
|
||
buildOutletFunction(this.req, this.res, data, options, config); | ||
// Get access to `sails` | ||
var sails = req._sails; | ||
|
||
// Set status code | ||
res.status(404); | ||
|
||
// If appropriate, serve data as JSON. | ||
This comment has been minimized.
Sorry, something went wrong.
mikermcneil
Member
|
||
if (req.wantsJSON) { | ||
return res.send(); | ||
} | ||
|
||
return res.view('404', function (err, html) { | ||
|
||
// If a view error occured, fall back to JSON. | ||
if (err) { | ||
// | ||
// Additionally: | ||
// • If the view was missing, ignore the error but provide a verbose log. | ||
if (err.code === 'E_VIEW_FAILED') { | ||
sails.log.verbose('res.notFound() :: Could not locate view for error page (sending text instead). Details: ', err); | ||
} | ||
// Otherwise, if this was a more serious error, log to the console with the details. | ||
else { | ||
sails.log.warn('res.notFound() :: When attempting to render error page view, an error occured (sending text instead). Details: ', err); | ||
} | ||
return res.send('NOT FOUND'); | ||
This comment has been minimized.
Sorry, something went wrong.
mikermcneil
Member
|
||
} | ||
|
||
return res.send(html); | ||
}); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
@sgress454 same as 510504e#commitcomment-20009294