@@ -5,6 +5,7 @@ import 'dart:typed_data';
55import 'package:http/http.dart' as http;
66import 'package:http/http.dart' ;
77import 'package:http_parser/http_parser.dart' show MediaType;
8+ import 'package:logging/logging.dart' ;
89import 'package:mime/mime.dart' ;
910import 'package:retry/retry.dart' ;
1011import 'package:storage_client/src/types.dart' ;
@@ -13,6 +14,7 @@ import 'file_io.dart' if (dart.library.js) './file_stub.dart';
1314
1415class Fetch {
1516 final Client ? httpClient;
17+ final _log = Logger ('supabase.storage' );
1618
1719 Fetch ([this .httpClient]);
1820
@@ -25,18 +27,24 @@ class Fetch {
2527 return MediaType .parse (mime ?? 'application/octet-stream' );
2628 }
2729
28- StorageException _handleError (dynamic error, StackTrace stack) {
30+ StorageException _handleError (dynamic error, StackTrace stack, Uri ? url ) {
2931 if (error is http.Response ) {
3032 try {
3133 final data = json.decode (error.body) as Map <String , dynamic >;
32- return StorageException .fromJson (data, '${error .statusCode }' );
34+
35+ final exception =
36+ StorageException .fromJson (data, '${error .statusCode }' );
37+ _log.fine ('StorageException for $url ' , exception, stack);
38+ return exception;
3339 } on FormatException catch (_) {
40+ _log.fine ('StorageException for $url ' , error.body, stack);
3441 return StorageException (
3542 error.body,
3643 statusCode: '${error .statusCode }' ,
3744 );
3845 }
3946 } else {
47+ _log.fine ('StorageException for $url ' , error, stack);
4048 return StorageException (
4149 error.toString (),
4250 statusCode: error.runtimeType.toString (),
@@ -61,6 +69,7 @@ class Fetch {
6169 request.body = json.encode (body);
6270 }
6371
72+ _log.finest ('Request: $method $url $headers ' );
6473 final http.StreamedResponse streamedResponse;
6574 if (httpClient != null ) {
6675 streamedResponse = await httpClient! .send (request);
@@ -97,8 +106,11 @@ class Fetch {
97106
98107 final http.StreamedResponse streamedResponse;
99108 final r = RetryOptions (maxAttempts: (retryAttempts + 1 ));
109+ var attempts = 0 ;
100110 streamedResponse = await r.retry< http.StreamedResponse > (
101111 () async {
112+ attempts++ ;
113+ _log.finest ('Request: attempt: $attempts $method $url $headers ' );
102114 if (httpClient != null ) {
103115 return httpClient! .send (request);
104116 } else {
@@ -141,8 +153,11 @@ class Fetch {
141153
142154 final http.StreamedResponse streamedResponse;
143155 final r = RetryOptions (maxAttempts: (retryAttempts + 1 ));
156+ var attempts = 0 ;
144157 streamedResponse = await r.retry< http.StreamedResponse > (
145158 () async {
159+ attempts++ ;
160+ _log.finest ('Request: attempt: $attempts $method $url $headers ' );
146161 if (httpClient != null ) {
147162 return httpClient! .send (request);
148163 } else {
@@ -170,7 +185,7 @@ class Fetch {
170185 return jsonBody;
171186 }
172187 } else {
173- throw _handleError (response, StackTrace .current);
188+ throw _handleError (response, StackTrace .current, response.request ? .url );
174189 }
175190 }
176191
0 commit comments