protected function handleAPIError(\Psr\Http\Message\ResponseInterface $response, $body, ?\CharlotteDunois\Yasmin\Interfaces\RatelimitBucketInterface $ratelimit = null) {
        $status = $response->getStatusCode();
        
        if($status >= 500) {
            $this->retries++;
            $maxRetries = (int) $this->api->client->getOption('http.requestMaxRetries', 0);
            
            if($maxRetries > 0 && $this->retries > $maxRetries) {
                $this->api->client->emit('debug', 'Giving up on item "'.$this->endpoint.'" after '.$maxRetries.' retries due to HTTP '.$status);
                
                return (new \RuntimeException('Maximum retry of '.$maxRetries.' reached - giving up'));
            }
            
            $this->api->client->emit('debug', 'Delaying unshifting item "'.$this->endpoint.'" due to HTTP '.$status);
            
            $delay = (int) $this->api->client->getOption('http.requestErrorDelay', 30);
            if($this->retries > 2) {
                $delay *= 2;
            }
            
            $this->api->client->addTimer($delay, function () use (&$ratelimit) {
                if($ratelimit !== null) {
                    $this->api->unshiftQueue($ratelimit->unshift($this));
                } else {
                    $this->api->unshiftQueue($this);
                }
            });
            
            return null;
        } elseif($status === 429) {
            $this->api->client->emit('debug', 'Unshifting item "'.$this->endpoint.'" due to HTTP 429');
            
            if($ratelimit !== null) {
                $this->api->unshiftQueue($ratelimit->unshift($this));
            } else {
                $this->api->unshiftQueue($this);
            }
            
            return null;
        }
        
        if($status >= 400 && $status < 500) {
            $error = new \CharlotteDunois\Yasmin\HTTP\DiscordAPIException($this->endpoint, $body);
        } else {
            $error = new \RuntimeException($response->getReasonPhrase());
        }
        
        return $error;
    }