File tree Expand file tree Collapse file tree 3 files changed +20
-8
lines changed Expand file tree Collapse file tree 3 files changed +20
-8
lines changed Original file line number Diff line number Diff line change @@ -30,7 +30,13 @@ class Fetch {
3030 StackTrace stack,
3131 FetchOptions ? options,
3232 ) {
33- if (error is http.Response && ! (options? .noResolveJson == true )) {
33+ if (error is http.Response ) {
34+ if (options? .noResolveJson == true ) {
35+ return StorageException (
36+ error.body.isEmpty ? error.reasonPhrase ?? '' : error.body,
37+ statusCode: '${error .statusCode }' ,
38+ );
39+ }
3440 try {
3541 final data = json.decode (error.body) as Map <String , dynamic >;
3642 return StorageException .fromJson (data, '${error .statusCode }' );
Original file line number Diff line number Diff line change @@ -413,11 +413,18 @@ class StorageFileApi {
413413 Future <bool > exists (String path) async {
414414 final finalPath = _getFinalPath (path);
415415 final options = FetchOptions (headers: headers);
416- final response = await _storageFetch.head (
417- '$url /object/$finalPath ' ,
418- options: options,
419- );
420- return true ;
416+ try {
417+ await _storageFetch.head (
418+ '$url /object/$finalPath ' ,
419+ options: options,
420+ );
421+ return true ;
422+ } on StorageException catch (e) {
423+ if (e.statusCode == '400' || e.statusCode == '404' ) {
424+ return false ;
425+ }
426+ rethrow ;
427+ }
421428 }
422429
423430 /// Retrieve URLs for assets in public buckets
@@ -481,7 +488,6 @@ class StorageFileApi {
481488 body,
482489 options: options,
483490 );
484- print (response[0 ]);
485491 final fileObjects = List <FileObject >.from (
486492 (response as List ).map (
487493 (item) => FileObject .fromJson (item),
Original file line number Diff line number Diff line change @@ -410,7 +410,7 @@ void main() {
410410 });
411411
412412 test ('check if object exists' , () async {
413- await storage.from (newBucketName).upload (uploadPath, file);
413+ await storage.from (newBucketName).upload ('$ uploadPath -exists' , file);
414414 final res = await storage.from (newBucketName).exists (uploadPath);
415415 expect (res, true );
416416
You can’t perform that action at this time.
0 commit comments