- If there is no Retry-After header, returns 0
- If there is, returns seconds to delay, rounding up, minimum 1
- If Retry-After header is not an integer or a Date, (should not happen) throws an Error.
const parse_retry_after = require('parse-retry-after'); // or import...
fetch(URL, init)
.then(function(response) {
// probably want to save response somewhere somehow...
// check response.status
if (mightBeARetry) {
let delaySeconds = parse_retry_after(response);
if (delaySeconds) {
//delay and call fetch again...
}
}
else {
// normal "happy path" code
}
})
- Currently uses
module.exports
, should probably use ES6export
- see parse-retry-after6.mjs for first pass at an ES6 export.