httpRetryCodes; $httpRetryMessages = $this->httpRetryMessages; return function (\Exception $ex) use ($httpRetryCodes, $httpRetryMessages, $shouldRetryMessages) { $statusCode = $ex->getCode(); if (in_array($statusCode, $httpRetryCodes)) { return true; } if (!$shouldRetryMessages) { return false; } $message = ($ex instanceof RequestException && $ex->hasResponse()) ? (string) $ex->getResponse()->getBody() : $ex->getMessage(); try { $message = $this->jsonDecode( $message, true ); } catch (\InvalidArgumentException $ex) { return false; } if (!isset($message['errors'])) { return false; } foreach ($message['errors'] as $error) { if (in_array($error['reason'], $httpRetryMessages)) { return true; } } return false; }; } }