From 53537822de85a58fc9babe29a349edbc46590351 Mon Sep 17 00:00:00 2001 From: chris48s Date: Sun, 27 Aug 2023 21:37:56 +0100 Subject: [PATCH] log an error to sentry if an upstream service responds with `429 Too Many Requests` (#9505) * log an error to sentry if an upstream service responds with 429 Too Many Requests * fix tests --- core/base-service/check-error-response.js | 8 ++++++++ core/base-service/check-error-response.spec.js | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/core/base-service/check-error-response.js b/core/base-service/check-error-response.js index 62b6b695775da..08753f6ecb3ce 100644 --- a/core/base-service/check-error-response.js +++ b/core/base-service/check-error-response.js @@ -1,3 +1,4 @@ +import log from '../server/log.js' import { NotFound, InvalidResponse, Inaccessible } from './errors.js' const defaultErrorMessages = { @@ -25,6 +26,13 @@ export default function checkErrorResponse(httpErrors = {}) { error = new InvalidResponse(props) } } + + if (res.statusCode === 429) { + log.error( + new Error(`429 Too Many Requests calling ${res.requestUrl.origin}`), + ) + } + if (error) { error.response = res error.buffer = buffer diff --git a/core/base-service/check-error-response.spec.js b/core/base-service/check-error-response.spec.js index ba5d9a33e9b43..411008dfd6fd0 100644 --- a/core/base-service/check-error-response.spec.js +++ b/core/base-service/check-error-response.spec.js @@ -47,7 +47,7 @@ describe('async error handler', function () { context('when status is 429', function () { const buffer = Buffer.from('some stuff') - const res = { statusCode: 429 } + const res = { statusCode: 429, requestUrl: new URL('https://example.com/') } it('throws InvalidResponse', async function () { try {