Skip to content

Http chaining doesn't work correctly with native Illuminate client #1

@trevorkwhite

Description

@trevorkwhite

Hi there!

Thanks so much for the great package. I'm running into a weird issue on 0.2 when chaining rate limiting and retry strategy, or anything else.

Take for example, this code:

return Http::withRetryStrategy($strategy, [
            'max_attempts' => 5,
            'base_delay' => 2.5,  // Configures the baseDelay parameter of the underlying strategy
            'timeout' => 15,
        ])->withHeaders($headers)

It works fine and the retry strategy is correctly implemented.

However, when I try this --

return Http::withHeaders($headers)->withRetryStrategy($strategy, [
            'max_attempts' => 5,
            'base_delay' => 2.5,  // Configures the baseDelay parameter of the underlying strategy
            'timeout' => 15,
        ]);

I get the following:


  Method Illuminate\Http\Client\PendingRequest::withRetryStrategy does not exist.

  at vendor/laravel/framework/src/Illuminate/Macroable/Traits/Macroable.php:112
    108▕      */
    109▕     public function __call($method, $parameters)
    110▕     {
    111▕         if (! static::hasMacro($method)) {
  ➜ 112▕             throw new BadMethodCallException(sprintf(
    113▕                 'Method %s::%s does not exist.', static::class, $method
    114▕             ));
    115▕         }
    116▕```

Interestingly, I have the same problem when I try to chain `withRetryStrategy` combined with `withRateLimitHandling`

    return Http::withRetryStrategy($strategy, [
        'max_attempts' => 5,
        'base_delay' => 2.5,  // Configures the baseDelay parameter of the underlying strategy
        'timeout' => 15,
    ])->withRateLimitHandling()->withHeaders($headers);

This code also fails with BadMethodCall to withRateLimitHandling. I'm fairly new to php and Laravel, working on a Laravel 10 app, so please let me know if I'm doing something idiotic here, but I did confirm that other method chaining works fine --

return Http::withHeaders($headers)->withUserAgent('1234');


PHP 8.1, Laravel 10

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions