2
1
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2023-12-13 21:00:40 +01:00

🎨 error improvements (#7600)

*   id for each error instance
- copy paste of ignition
- on purpose for now
- delete TODO, wohoo
- use id property instead of uid, see http://jsonapi.org/format/#errors

* 🕵🏻  remove TODO for decouple req.err
- can't find a nicer alternative solution
- added some more descriptions to code pieces in our error-handler

* 🎨  use uuid.v1
- timestamp based
This commit is contained in:
Katharina Irrgang 2016-10-21 14:10:17 +02:00 committed by Hannah Wolfe
parent 02a1f08ba3
commit 2887602712
2 changed files with 7 additions and 4 deletions

View file

@ -1,4 +1,5 @@
var _ = require('lodash'),
uuid = require('node-uuid'),
util = require('util');
function GhostError(options) {
@ -14,11 +15,11 @@ function GhostError(options) {
/**
* defaults
* @TODO: I'd like to add the usage of an individual ID to errors, as we have in ignition
*/
this.statusCode = 500;
this.errorType = 'InternalServerError';
this.level = 'normal';
this.id = uuid.v1();
/**
* custom overrides

View file

@ -51,8 +51,7 @@ _private.parseStack = function parseStack(stack) {
/**
* Get an error ready to be shown the the user
*
* @TODO: support multiple errors
* @TODO: decouple req.err
* @TODO: support multiple errors within one single error, see https://github.com/TryGhost/Ghost/issues/7116#issuecomment-252231809
*/
_private.prepareError = function prepareError(err, req, res, next) {
if (_.isArray(err)) {
@ -74,7 +73,10 @@ _private.prepareError = function prepareError(err, req, res, next) {
}
}
// used for express logging middleware see core/server/app.js
req.err = err;
// alternative for res.status();
res.statusCode = err.statusCode;
// never cache errors
@ -86,7 +88,7 @@ _private.prepareError = function prepareError(err, req, res, next) {
};
_private.JSONErrorRenderer = function JSONErrorRenderer(err, req, res, /*jshint unused:false */ next) {
// @TODO: jsonapi errors format ?
// @TODO: jsonapi errors format (http://jsonapi.org/format/#error-objects)
res.json({
errors: [{
message: err.message,