# Net::Twitter::Role::RetryOnError - Retry Twitter API calls on error - perldoc - [phpMan]

## NAME
    [Net::Twitter::Role::RetryOnError](https://www.chedong.com/phpMan.php/perldoc/Net%3A%3ATwitter%3A%3ARole%3A%3ARetryOnError/markdown) - Retry Twitter API calls on error

## VERSION
    version 4.01043

## SYNOPSIS
        use [Net::Twitter](https://www.chedong.com/phpMan.php/perldoc/Net%3A%3ATwitter/markdown);
        $nt = [Net::Twitter](https://www.chedong.com/phpMan.php/perldoc/Net%3A%3ATwitter/markdown)->new(
            traits      => ['[API::RESTv1_1](https://www.chedong.com/phpMan.php/perldoc/API%3A%3ARESTv11/markdown)', 'RetryOnError']
            max_retries => 3,
        );

## DESCRIPTION
    Temporary errors are not uncommon when calling the Twitter API. When applied to [Net::Twitter](https://www.chedong.com/phpMan.php/perldoc/Net%3A%3ATwitter/markdown)
    this role will provide automatic retries of API calls in a very configurable way.

    It only retries when the response status code is >= 500. Other error codes indicate a permanent
    error. If the maximum number of retries is reached, without success, an exception is thrown, as
    usual.

## OPTIONS
    This role adds the following options to "new":

    initial_retry_delay
        A floating point number specifying the initial delay, after an error, before retrying.
        Default: 0.25 (250 milliseconds).

    max_retry_delay
        A floating point number specifying the maximum delay between retries. Default: 4.0

    retry_delay_multiplier
        On the second and subsequent retries, a new delay is calculated by multiplying the previous
        delay by "retry_delay_multiplier". Default: 2.0

    max_retries
        The maximum number of consecutive retries before giving up and throwing an exception. If set
        to 0, it the API call will be retried indefinitely. Default 5.

    retry_delay_code
        A code reference that will be called to handle the delay. It is passed a single argument: a
        floating point number specifying the number of seconds to delay. By default, "sleep" in
        [Time::HiRes](https://www.chedong.com/phpMan.php/perldoc/Time%3A%3AHiRes/markdown) is called.

        If you're using a non-blocking user agent, like [Coro::LWP](https://www.chedong.com/phpMan.php/perldoc/Coro%3A%3ALWP/markdown), you should use this option to
        provide a non-blocking delay.

## AUTHOR
    Marc Mims <<marc@questright.com>>

## COPYRIGHT
    Copyright (c) 2016 Marc Mims

## LICENSE
    This library is free software and may be distributed under the same terms as perl itself.

