[GH-ISSUE #240] cURL handle closed before calling curl_errno and curl_error #172

Closed
opened 2026-02-27 19:26:26 +03:00 by kerem · 1 comment
Owner

Originally created by @sjerdo on GitHub (Nov 28, 2021).
Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/240

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);
        }
Originally created by @sjerdo on GitHub (Nov 28, 2021). Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/240 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](https://github.com/jwilsson/spotify-web-api-php/blob/main/src/Request.php#L221-L223) ```php 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. ```php if (curl_error($ch)) { $error = curl_error($ch); $errno = curl_errno($ch); curl_close($ch); throw new SpotifyWebAPIException('cURL transport error: ' . $errno . ' ' .$error); } ```
kerem 2026-02-27 19:26:26 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@jwilsson commented on GitHub (Nov 30, 2021):

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

<!-- gh-comment-id:982325522 --> @jwilsson commented on GitHub (Nov 30, 2021): Hi! Nice catch! Would you like to send a PR with those changes?
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotify-web-api-php#172
No description provided.