mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Re-throw error when attempting to create webhooks
- we catch error arising from creating webhooks and check for specific codes - if our error does not match one of those codes, we don't propagate the error up - this becomes a problem if saving a webhook fails for some other reason because upstream code assumes we return an error or model - this commit re-throws the error and adds a test that would have caught this
This commit is contained in:
parent
a7074592c8
commit
1a3aa69c68
2 changed files with 39 additions and 0 deletions
|
@ -41,6 +41,8 @@ class WebhooksService {
|
|||
help: messages.nonExistingIntegrationIdProvided.help
|
||||
});
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
37
test/unit/server/services/webhooks/webhook-service.test.js
Normal file
37
test/unit/server/services/webhooks/webhook-service.test.js
Normal file
|
@ -0,0 +1,37 @@
|
|||
const errors = require('@tryghost/errors');
|
||||
const should = require('should');
|
||||
const sinon = require('sinon');
|
||||
|
||||
const createWebhookService = require('../../../../../core/server/services/webhooks/webhooks-service');
|
||||
const models = require('../../../../../core/server/models');
|
||||
|
||||
describe('Webhook Service', function () {
|
||||
before(models.init);
|
||||
|
||||
afterEach(function () {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
it('re-throws any unhandled errors', async function () {
|
||||
sinon.stub(models.Webhook, 'getByEventAndTarget').resolves(null);
|
||||
sinon.stub(models.Webhook, 'add').throws('CustomTestError');
|
||||
|
||||
const webhookService = createWebhookService({WebhookModel: models.Webhook});
|
||||
|
||||
const fakeWebhook = {
|
||||
webhooks: [
|
||||
{
|
||||
event: 'post.published',
|
||||
target_url: 'http://example.com/webhook'
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
try {
|
||||
await webhookService.add(fakeWebhook, {});
|
||||
should.fail('should have thrown');
|
||||
} catch (err) {
|
||||
err.name.should.equal('CustomTestError');
|
||||
}
|
||||
});
|
||||
});
|
Loading…
Add table
Reference in a new issue