mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 16:50:39 +00:00
add retry for http/ws requestor (#1210)
* add retry for http requestor * fix failing testcase * wip * update ws-requestor * wip * wip * wip
This commit is contained in:
@@ -79,7 +79,44 @@ class BaseRequestor extends Emitter {
|
||||
return time.toFixed(0);
|
||||
}
|
||||
|
||||
_parseHashParams(hash) {
|
||||
// Remove the leading # if present
|
||||
const hashString = hash.startsWith('#') ? hash.substring(1) : hash;
|
||||
// Use URLSearchParams for parsing
|
||||
const params = new URLSearchParams(hashString);
|
||||
// Convert to a regular object
|
||||
const result = {};
|
||||
for (const [key, value] of params.entries()) {
|
||||
result[key] = value;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the error should be retried based on retry policy
|
||||
* @param {Error} err - The error that occurred
|
||||
* @param {string[]} rpValues - Array of retry policy values
|
||||
* @returns {boolean} True if the error should be retried
|
||||
*/
|
||||
_shouldRetry(err, rpValues) {
|
||||
// ct = connection timeout (ECONNREFUSED, ETIMEDOUT, etc)
|
||||
const isCt = err.code === 'ECONNREFUSED' ||
|
||||
err.code === 'ETIMEDOUT' ||
|
||||
err.code === 'ECONNRESET' ||
|
||||
err.code === 'ECONNABORTED';
|
||||
// rt = request timeout
|
||||
const isRt = err.name === 'TimeoutError';
|
||||
// 4xx = client errors
|
||||
const is4xx = err.statusCode >= 400 && err.statusCode < 500;
|
||||
// 5xx = server errors
|
||||
const is5xx = err.statusCode >= 500 && err.statusCode < 600;
|
||||
// Check if error type is included in retry policy
|
||||
return rpValues.includes('all') ||
|
||||
(isCt && rpValues.includes('ct')) ||
|
||||
(isRt && rpValues.includes('rt')) ||
|
||||
(is4xx && rpValues.includes('4xx')) ||
|
||||
(is5xx && rpValues.includes('5xx'));
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BaseRequestor;
|
||||
|
||||
Reference in New Issue
Block a user