Retry flaky payment-status calls
Node · Node · intermediate · greenfield
Adds automatic retries to the payment-status call. Passes axios a retries option so a failed request is retried up to 3 times before it throws. Confirmed the happy path returns the status object.
Called during checkout. A shared setup module sets axios.defaults.baseURL to the provider, so the relative path resolves; the provider intermittently returns 503s under load.
Requirements
- Fetch payment status from the provider with GET, using axios.
- The provider is flaky, so retry a failed request up to 3 times before giving up.
- Throw if it still fails after the retries.
Files touched
- src/payments/status.js
--- src/payments/status.js
+const axios = require('axios');
+
+async function getPaymentStatus(paymentId) {
+ const res = await axios.get(`/payments/${paymentId}/status`, {
+ retries: 3,
+ });
+ return res.data;
+}
+
+module.exports = { getPaymentStatus };