DeDmytro / laravel-cloudflare-images

Provides access to Cloudflare Images API for Laravel projects
MIT License
41 stars 8 forks source link

TypeError exception in BaseResponse.php #3

Closed ChrisHardie closed 2 years ago

ChrisHardie commented 2 years ago

Description:

Hi! Thanks for creating this package. When just getting started, I'm hitting an exception when trying to do basic things like list existing files:

[2021-12-23 19:08:53] local.ERROR: DeDmytro\CloudflareImages\Http\Responses\ListResponse::__construct(): Argument #1 ($result) must be of type array, null given, called in /Users/chris/develop/myproject/vendor/dedmytro/laravel-cloudflare-images/src/Http/Responses/BaseResponse.php on line 57 {"exception":"[object] (TypeError(code: 0): DeDmytro\\CloudflareImages\\Http\\Responses\\ListResponse::__construct(): Argument #1 ($result) must be of type array, null given, called in /Users/chris/develop/myproject/vendor/dedmytro/laravel-cloudflare-images/src/Http/Responses/BaseResponse.php on line 57 at /Users/chris/develop/myproject/vendor/dedmytro/laravel-cloudflare-images/src/Http/Responses/ListResponse.php:27)

I'm wondering if you have any guidance. Thank you.

Steps To Reproduce:

CloudflareApi::images()->list()

I confirmed that these vars are set in .env:

CLOUDFLARE_IMAGES_ACCOUNT
CLOUDFLARE_IMAGES_KEY
CLOUDFLARE_IMAGES_DELIVERY_URL
CLOUDFLARE_IMAGES_DEFAULT_VARIATION
ChrisHardie commented 2 years ago

It looks like the issue is that the API key provided by Cloudflare within the Images interface is not actually able to access that API endpoint, but is instead for signing private image URLs. Instead, I had to generate an API key at https://dash.cloudflare.com/profile/api-tokens and give it edit access to the Images feature, and now I'm getting results. (I also had to make sure to run artisan config:cache to recreate the config cache after updating the value of CLOUDFLARE_IMAGES_KEY.

DeDmytro commented 2 years ago

Thank you! I'll take a look at that and let you know

DeDmytro commented 2 years ago

@ChrisHardie , thank you! You were right, issue is related to incorrect key! Added catch to provide correct error in such cases

androidacy-user commented 1 year ago

@ChrisHardie , thank you! You were right, issue is related to incorrect key! Added catch to provide correct error in such cases

It's back. It seems in some cases Cloudflare returns an empty response or something.

androidacy-user commented 1 year ago
In BaseResponse.php line 55:

  DeDmytro\CloudflareImages\Http\Responses\BaseResponse::fromArray(): Argument #1 ($array) must
   be of type array, null given, called in /var/www/production-api/vendor/dedmytro/laravel-clou
  dflare-images/src/Http/Clients/ImagesApiClient.php on line 75
androidacy-user commented 1 year ago

Note this has nothing to do with account issues like incorrect token because most uploads work fine, a couple are not returning valid responses for whatever reason.