Skip to content

Commit

Permalink
🐛 Use isIgnitionError to detect unhandled errors (#8100)
Browse files Browse the repository at this point in the history
closes #8099, refs TryGhost/Ignition#28

- use new utility to detect if an error has not yet been handled & convert it to a generic Ghost error
- update theme_spec tests to include checking error messages, which catches this issue
  • Loading branch information
ErisDS authored and kirrg001 committed Mar 6, 2017
1 parent fdcc66b commit 9aec9c6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion core/server/middleware/error-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ _private.prepareError = function prepareError(err, req, res, next) {
err = err[0];
}

if (!(err instanceof errors.GhostError)) {
if (!errors.utils.isIgnitionError(err)) {
// We need a special case for 404 errors
// @TODO look at adding this to the GhostError class
if (err.statusCode && err.statusCode === 404) {
Expand Down
20 changes: 18 additions & 2 deletions core/test/functional/routes/api/themes_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,12 @@ describe('Themes API', function () {
}

res.statusCode.should.eql(403);

should.exist(res.body.errors);
res.body.errors.should.be.an.Array().with.lengthOf(1);
res.body.errors[0].errorType.should.eql('NoPermissionError');
res.body.errors[0].message.should.eql('You do not have permission to add themes');

done();
});
});
Expand All @@ -263,11 +269,16 @@ describe('Themes API', function () {
request.del(testUtils.API.getApiQuery('themes/test'))
.set('Authorization', 'Bearer ' + scope.editorAccessToken)
.expect(403)
.end(function (err) {
.end(function (err, res) {
if (err) {
return done(err);
}

should.exist(res.body.errors);
res.body.errors.should.be.an.Array().with.lengthOf(1);
res.body.errors[0].errorType.should.eql('NoPermissionError');
res.body.errors[0].message.should.eql('You do not have permission to destroy themes');

done();
});
});
Expand All @@ -276,11 +287,16 @@ describe('Themes API', function () {
request.get(testUtils.API.getApiQuery('themes/casper/download/'))
.set('Authorization', 'Bearer ' + scope.editorAccessToken)
.expect(403)
.end(function (err) {
.end(function (err, res) {
if (err) {
return done(err);
}

should.exist(res.body.errors);
res.body.errors.should.be.an.Array().with.lengthOf(1);
res.body.errors[0].errorType.should.eql('NoPermissionError');
res.body.errors[0].message.should.eql('You do not have permission to read themes');

done();
});
});
Expand Down

0 comments on commit 9aec9c6

Please sign in to comment.