0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Improve error handling for authentication

closes #3660
- added wrapping in JSON API format to error500()
- added client side handling
This commit is contained in:
Sebastian Gierlinger 2014-08-08 09:44:24 +02:00
parent a65cc15e56
commit 649a0872ec
2 changed files with 22 additions and 7 deletions

View file

@ -25,7 +25,12 @@ var ApplicationRoute = Ember.Route.extend(SimpleAuth.ApplicationRouteMixin, Shor
},
sessionAuthenticationFailed: function (error) {
this.notifications.showError(error.message);
if (error.errors) {
this.notifications.showErrors(error.errors);
} else {
// connection errors don't return proper status message, only req.body
this.notifications.showError('There was a problem on the server.');
}
},
sessionAuthenticationSucceeded: function () {

View file

@ -275,15 +275,25 @@ errors = {
}
errors.renderErrorPage(err.status || 500, err, req, res, next);
} else {
// generate a valid JSON response
var statusCode = 500,
errorContent = {};
returnErrors = [];
statusCode = err.code || 500;
if (!_.isArray(err)) {
err = [].concat(err);
}
errorContent.message = _.isString(err) ? err : (_.isObject(err) ? err.message : 'Unknown Error');
errorContent.type = err.type || 'InternalServerError';
res.json(statusCode, errorContent);
_.each(err, function (errorItem) {
var errorContent = {};
statusCode = errorItem.code || 500;
errorContent.message = _.isString(errorItem) ? errorItem :
(_.isObject(errorItem) ? errorItem.message : 'Unknown Error');
errorContent.type = errorItem.type || 'InternalServerError';
returnErrors.push(errorContent);
});
res.json(statusCode, {errors: returnErrors});
}
}
};