mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05: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:
parent
02a1f08ba3
commit
2887602712
2 changed files with 7 additions and 4 deletions
|
@ -1,4 +1,5 @@
|
||||||
var _ = require('lodash'),
|
var _ = require('lodash'),
|
||||||
|
uuid = require('node-uuid'),
|
||||||
util = require('util');
|
util = require('util');
|
||||||
|
|
||||||
function GhostError(options) {
|
function GhostError(options) {
|
||||||
|
@ -14,11 +15,11 @@ function GhostError(options) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* defaults
|
* defaults
|
||||||
* @TODO: I'd like to add the usage of an individual ID to errors, as we have in ignition
|
|
||||||
*/
|
*/
|
||||||
this.statusCode = 500;
|
this.statusCode = 500;
|
||||||
this.errorType = 'InternalServerError';
|
this.errorType = 'InternalServerError';
|
||||||
this.level = 'normal';
|
this.level = 'normal';
|
||||||
|
this.id = uuid.v1();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* custom overrides
|
* custom overrides
|
||||||
|
|
|
@ -51,8 +51,7 @@ _private.parseStack = function parseStack(stack) {
|
||||||
/**
|
/**
|
||||||
* Get an error ready to be shown the the user
|
* Get an error ready to be shown the the user
|
||||||
*
|
*
|
||||||
* @TODO: support multiple errors
|
* @TODO: support multiple errors within one single error, see https://github.com/TryGhost/Ghost/issues/7116#issuecomment-252231809
|
||||||
* @TODO: decouple req.err
|
|
||||||
*/
|
*/
|
||||||
_private.prepareError = function prepareError(err, req, res, next) {
|
_private.prepareError = function prepareError(err, req, res, next) {
|
||||||
if (_.isArray(err)) {
|
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;
|
req.err = err;
|
||||||
|
|
||||||
|
// alternative for res.status();
|
||||||
res.statusCode = err.statusCode;
|
res.statusCode = err.statusCode;
|
||||||
|
|
||||||
// never cache errors
|
// 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) {
|
_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({
|
res.json({
|
||||||
errors: [{
|
errors: [{
|
||||||
message: err.message,
|
message: err.message,
|
||||||
|
|
Loading…
Add table
Reference in a new issue