Skip to content

Commit

Permalink
🎨 error improvements (#7600)
Browse files Browse the repository at this point in the history
* ✨  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
  • Loading branch information
kirrg001 authored and ErisDS committed Oct 21, 2016
1 parent 02a1f08 commit 2887602
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion core/server/errors.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var _ = require('lodash'),
uuid = require('node-uuid'),
util = require('util');

function GhostError(options) {
Expand All @@ -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
Expand Down
8 changes: 5 additions & 3 deletions core/server/middleware/error-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit 2887602

Please sign in to comment.