From 645958bbeb25c9feadd7d95e58a05b501b3e6a1e Mon Sep 17 00:00:00 2001 From: Matt Fiddaman Date: Fri, 6 Dec 2024 21:29:26 +0000 Subject: [PATCH] Return GoCardless rate limit information on error (#509) --- src/app-gocardless/app-gocardless.js | 13 ++++++++++++- upcoming-release-notes/509.md | 6 ++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 upcoming-release-notes/509.md diff --git a/src/app-gocardless/app-gocardless.js b/src/app-gocardless/app-gocardless.js index cabeffcd6..b076a91b5 100644 --- a/src/app-gocardless/app-gocardless.js +++ b/src/app-gocardless/app-gocardless.js @@ -201,8 +201,19 @@ app.post( }); } } catch (error) { + const headers = error.details?.response?.headers ?? {}; + + const rateLimitHeaders = Object.fromEntries( + Object.entries(headers).filter(([key]) => + key.startsWith('http_x_ratelimit'), + ), + ); + const sendErrorResponse = (data) => - res.send({ status: 'ok', data: { ...data, details: error.details } }); + res.send({ + status: 'ok', + data: { ...data, details: error.details, rateLimitHeaders }, + }); switch (true) { case error instanceof RequisitionNotLinked: diff --git a/upcoming-release-notes/509.md b/upcoming-release-notes/509.md new file mode 100644 index 000000000..91e2afe47 --- /dev/null +++ b/upcoming-release-notes/509.md @@ -0,0 +1,6 @@ +--- +category: Enhancements +authors: [matt-fidd] +--- + +Add more logging for GoCardless rate limit information