public static function createStatusFilter(
        array $failureStatuses = [500, 503]
    ) {
        // Convert the array of values into a set for hash lookups
        $failureStatuses = array_fill_keys($failureStatuses, true);

        return function (
            $retries,
            AbstractTransferEvent $event
        ) use ($failureStatuses) {
            if (!($response = $event->getResponse())) {
                return false;
            }
            return isset($failureStatuses[$response->getStatusCode()]);
        };
    }