Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839
  1. 'use strict'
  2. const retry = require('p-retry')
  3. const defaultProfile = require('./lib/default-profile')
  4. const retryDefaults = {
  5. retries: 3,
  6. factor: 3,
  7. minTimeout: 5 * 1000
  8. }
  9. const withRetrying = (profile, retryOpts = {}) => {
  10. retryOpts = Object.assign({}, retryDefaults, retryOpts)
  11. // https://github.com/public-transport/hafas-client/issues/76#issuecomment-574408717
  12. const {request} = {...defaultProfile, ...profile}
  13. const retryingRequest = (...args) => {
  14. const attempt = () => {
  15. return request(...args)
  16. .catch((err) => {
  17. if (err.isHafasError) throw err // continue
  18. if (err.code === 'ENOTFOUND') { // abort
  19. const abortErr = new retry.AbortError(err)
  20. Object.assign(abortErr, err)
  21. throw abortErr
  22. }
  23. throw err // continue
  24. })
  25. }
  26. return retry(attempt, retryOpts)
  27. }
  28. return {
  29. ...profile,
  30. request: retryingRequest
  31. }
  32. }
  33. module.exports = withRetrying