diff --git a/core/server/services/webhooks/webhooks-service.js b/core/server/services/webhooks/webhooks-service.js index 979e226788..37a8600fdf 100644 --- a/core/server/services/webhooks/webhooks-service.js +++ b/core/server/services/webhooks/webhooks-service.js @@ -41,6 +41,8 @@ class WebhooksService { help: messages.nonExistingIntegrationIdProvided.help }); } + + throw error; } } } diff --git a/test/unit/server/services/webhooks/webhook-service.test.js b/test/unit/server/services/webhooks/webhook-service.test.js new file mode 100644 index 0000000000..680aa9b132 --- /dev/null +++ b/test/unit/server/services/webhooks/webhook-service.test.js @@ -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'); + } + }); +});