spatie / flysystem-dropbox

A flysystem driver for Dropbox that uses the v2 API
https://freek.dev/734-dropbox-will-turn-off-v1-of-their-api-soon-its-time-to-update-your-php-application
MIT License
342 stars 50 forks source link

List files exception #28

Closed TheNodi closed 6 years ago

TheNodi commented 6 years ago

I was using Laravel Backup to save my backup into a dropbox account. When calling backup:list before running any backup an exception was thrown:

[Spatie\Dropbox\Exceptions\BadRequest]  
  path/not_found/...

It turn out Dropbox is returning an error when listing files in a directory that doesn't exists.

Flysystem follows a Files First approach, and testing out using other drivers results in an empty array:

>>> Storage::disk('local')->allFiles('directory_not_found')
=> []
>>> Storage::disk('dropbox')->allFiles('directory_not_found')
Spatie\Dropbox\Exceptions\BadRequest with message 'path/not_found/'

This PR wraps dropbox call in a try-catch returning an empty array if BadRequest is thrown.

Reading dropbox documentation the only available error using this command is path LookupError, so there're only two possible errors here: not_found, not_folder.

I checked the behavior of the local driver when "listing files" given an existing file as path instead of a folder, it returns and empty array. So I assume catching all dropbox errors is consistent with Flysystem behavior.

freekmurze commented 6 years ago

Makes sense, thanks!