2

I'm posting this here because I couldn't find a good example/documentation on this subject. The official Supergent docs only say

This method has two optional arguments: number of retries (default 3) and a callback. It calls callback(err, res) before each retry. The callback may return true/false to control whether the request sould be retried (but the maximum number of retries is always applied).

I have the following questions regarding this functionality.

  1. What happens if there are no callback to the retry method eg: request.retry(); how does it decide when to retry?
  2. Does the true/false returned by the callback function decide whether to retry again?
  3. Is there a way to skip retrying if the request failed with specific error type, say 5xx?
  4. How can you have an async function as the callback?

Thanks

ben
  • 181
  • 1
  • 12

1 Answers1

0

To answer your questions:

  1. The code documentation says that retry is called under the following conditions:
/**
 * Set number of retry attempts on error.
 *
 * Failed requests will be retried 'count' times if timeout or err.code >= 500.
 *
 * @param {Number} count
 * @param {Function} [fn]
 * @return {Request} for chaining
 * @api public
 */

  1. Yes, return true to retry, false to not retry
  2. Yes, you can pass (err, res) into the callback and program that into the callback logic and return false on the desired error code.
  3. Upon my testing, no, you cannot use an async function as the callback to retry. It fails to retry. This would be a nice feature.
TetraDev
  • 16,074
  • 6
  • 60
  • 61