fix(core): Add custom 400 and 404 error messages (#1547)

* Added 400 and 404 custom error messages

* nicer error message views

* Sign Up & Sign In error responses

Changed the error responses returned from the Sign Up & Sign In API
calls to use 422 rather than 400.

For insight into why this change was made:
https://github.com/meanjs/mean/pull/1510#issuecomment-247435378

For reference on why to use 422 over 400:
https://www.bennadel.com/blog/2434-http-status-codes-for-invalid-data-400-vs-422.htm
This commit is contained in:
Michael Leanos
2016-10-07 22:03:31 -07:00
committed by GitHub
parent 8645b24397
commit 6be12f8a06
7 changed files with 55 additions and 9 deletions

View File

@@ -30,7 +30,7 @@ exports.signup = function (req, res) {
// Then save the user
user.save(function (err) {
if (err) {
return res.status(400).send({
return res.status(422).send({
message: errorHandler.getErrorMessage(err)
});
} else {
@@ -55,7 +55,7 @@ exports.signup = function (req, res) {
exports.signin = function (req, res, next) {
passport.authenticate('local', function (err, user, info) {
if (err || !user) {
res.status(400).send(info);
res.status(422).send(info);
} else {
// Remove sensitive data before login
user.password = undefined;