Skip to content

Commit

Permalink
Remove retry logic from axios formio response interceptor, as react-q…
Browse files Browse the repository at this point in the history
…uery internally has retry logic built-in, and fix setting of URL to be logged in error log
  • Loading branch information
courtneymyers committed Feb 28, 2024
1 parent 59946eb commit d3346ff
Showing 1 changed file with 1 addition and 22 deletions.
23 changes: 1 addition & 22 deletions app/server/app/config/formio.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@ const submissionPeriodOpen = {
function axiosFormio(req) {
const instance = axios.create();

/** NOTE: thanks to https://github.com/softonic/axios-retry for the retry logic. */
instance.interceptors.request.use((config) => {
config.csb = config.csb ?? {};
config.csb.retryCount = config.csb.retryCount || 0;

config.headers["x-token"] = FORMIO_API_KEY;
config.headers["b3"] = req.headers["b3"] || "";
config.headers["x-b3-traceid"] = req.headers["x-b3-traceid"] || "";
Expand All @@ -81,28 +77,11 @@ function axiosFormio(req) {
instance.interceptors.response.use(
(response) => response,
(error) => {
if (typeof error.toJSON === "function") {
log({ level: "debug", message: error.toJSON() });
}

/** Attempt to retry a failed request 3 times, and log the attempts. */
const { config } = error;
const { status } = error.response;

const { retryCount } = config.csb;
const method = config.method.toUpperCase();
const url = { config };

if (retryCount < 3) {
retryCount += 1;

const logMessage = `Formio Error: ${status} ${method} ${url} - Retrying (${retryCount} of 3)...`;
log({ level: "warn", message: logMessage, req: config });

return new Promise((resolve) =>
setTimeout(() => resolve(instance.request(config)), 1000),
);
}
const { url } = config;

const logMessage =
`Formio Error: ${status} ${method} ${url}. ` +
Expand Down

0 comments on commit d3346ff

Please sign in to comment.