From 58be6d23db72ff1c216513c35d88d40d4fdbe14a Mon Sep 17 00:00:00 2001 From: Thibaut Patel Date: Tue, 16 Feb 2021 15:31:44 +0100 Subject: [PATCH] Split the "Too many requests" error in ping service issue https://github.com/TryGhost/Team/issues/362 --- core/server/services/xmlrpc.js | 21 +++++++++++++++------ test/unit/services/xmlrpc_spec.js | 15 +++++++++++++++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/core/server/services/xmlrpc.js b/core/server/services/xmlrpc.js index a76f5454c2..e6d71b81c6 100644 --- a/core/server/services/xmlrpc.js +++ b/core/server/services/xmlrpc.js @@ -82,12 +82,21 @@ function ping(post) { } }) .catch(function (err) { - logging.error(new errors.GhostError({ - err: err, - message: err.message, - context: i18n.t('errors.services.ping.requestFailed.error', {service: 'xmlrpc'}), - help: i18n.t('errors.services.ping.requestFailed.help', {url: 'https://ghost.org/docs/'}) - })); + if (err.statusCode === 429) { + logging.error(new errors.TooManyRequestsError({ + err, + message: err.message, + context: i18n.t('errors.services.ping.requestFailed.error', {service: 'xmlrpc'}), + help: i18n.t('errors.services.ping.requestFailed.help', {url: 'https://ghost.org/docs/'}) + })); + } else { + logging.error(new errors.GhostError({ + err: err, + message: err.message, + context: i18n.t('errors.services.ping.requestFailed.error', {service: 'xmlrpc'}), + help: i18n.t('errors.services.ping.requestFailed.help', {url: 'https://ghost.org/docs/'}) + })); + } }); }); } diff --git a/test/unit/services/xmlrpc_spec.js b/test/unit/services/xmlrpc_spec.js index 61bbfab140..03c9d00db4 100644 --- a/test/unit/services/xmlrpc_spec.js +++ b/test/unit/services/xmlrpc_spec.js @@ -255,5 +255,20 @@ describe('XMLRPC', function () { setTimeout(retry, 100); }()); }); + + it('should behave correctly when getting a 429', function (done) { + const ping1 = nock('http://rpc.pingomatic.com').post('/').reply(429); + const testPost = _.clone(testUtils.DataGenerator.Content.posts[2]); + + ping(testPost); + + (function retry() { + if (ping1.isDone()) { + return done(); + } + + setTimeout(retry, 100); + }()); + }); }); });