mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-08-09 12:15:00 +08:00
Fix/axios abort signal for 1.23.X (#3971)
* Fix: Add axios abort signal * Chore: Fix comment --------- Co-authored-by: Nelson Chan <chakflying@hotmail.com>
This commit is contained in:
@@ -1124,3 +1124,26 @@ if (process.env.TEST_BACKEND) {
|
||||
return module.exports.__test[functionName];
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an abort signal with the specified timeout.
|
||||
* @param {number} timeoutMs - The timeout in milliseconds.
|
||||
* @returns {AbortSignal | null} - The generated abort signal, or null if not supported.
|
||||
*/
|
||||
module.exports.axiosAbortSignal = (timeoutMs) => {
|
||||
try {
|
||||
return AbortSignal.timeout(timeoutMs);
|
||||
} catch (_) {
|
||||
// v16-: AbortSignal.timeout is not supported
|
||||
try {
|
||||
const abortController = new AbortController();
|
||||
|
||||
setTimeout(() => abortController.abort(), timeoutMs || 0);
|
||||
|
||||
return abortController.signal;
|
||||
} catch (_) {
|
||||
// v15-: AbortController is not supported
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user