jwilsson / spotify-web-api-php

A PHP wrapper for Spotify's Web API.
MIT License
867 stars 156 forks source link

cURL handle closed before calling curl_errno and curl_error #240

Closed sjerdo closed 2 years ago

sjerdo commented 2 years ago

Hi Jonathan,

First of all, thanks for creating this API wrapper.

I experience the following error for some requests to https://accounts.spotify.com/api/token

Warning: curl_error(): supplied resource is not a valid cURL handle resource

It seems like the cURL handle is closed before getting the require curl_errno and curl_error information in Request.php lines 221 - 223

        if (curl_error($ch)) {
            curl_close($ch);

            throw new SpotifyWebAPIException('cURL transport error: ' . curl_errno($ch) . ' ' . curl_error($ch));
        }

I suggest changing this to first set these values or the error message in a variable, before closing the connection.

        if (curl_error($ch)) {
            $error = curl_error($ch);
            $errno = curl_errno($ch);

            curl_close($ch);

            throw new SpotifyWebAPIException('cURL transport error: ' . $errno . ' ' .$error);
        }
jwilsson commented 2 years ago

Hi! Nice catch! Would you like to send a PR with those changes?