Skip to content

Commit

Permalink
fix: compile with webdev (#653)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinzent03 committed Oct 5, 2023
1 parent 2ff950d commit 2324228
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 13 deletions.
6 changes: 3 additions & 3 deletions packages/gotrue/lib/src/gotrue_client.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'dart:math';

import 'package:collection/collection.dart';
Expand All @@ -13,7 +14,6 @@ import 'package:http/http.dart';
import 'package:jwt_decode/jwt_decode.dart';
import 'package:meta/meta.dart';
import 'package:rxdart/subjects.dart';
import 'package:universal_io/io.dart';

part 'gotrue_mfa_api.dart';

Expand All @@ -29,7 +29,7 @@ part 'gotrue_mfa_api.dart';
/// [asyncStorage] local storage to store pkce code verifiers. Required when using the pkce flow.
///
/// Set [flowType] to `AuthFlowType.pkce` to perform pkce auth flow.
/// /// {@endtemplate}
/// {@endtemplate}
class GoTrueClient {
/// Namespace for the GoTrue API methods.
/// These can be used for example to get a user from a JWT in a server environment or reset a user's password.
Expand Down Expand Up @@ -966,7 +966,7 @@ class GoTrueClient {
_notifyAllSubscribers(AuthChangeEvent.tokenRefreshed);
_refreshTokenCompleter!.complete(authResponse);
return authResponse;
} on SocketException {
} on ClientException {
_setTokenRefreshTimer(
Constants.retryInterval * pow(2, _refreshTokenRetryCount),
refreshToken: token,
Expand Down
1 change: 0 additions & 1 deletion packages/gotrue/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ dependencies:
crypto: ^3.0.2
http: '>=0.13.0 <2.0.0'
jwt_decode: ^0.3.1
universal_io: ^2.0.4
rxdart: ^0.27.7
meta: ^1.7.0

Expand Down
3 changes: 1 addition & 2 deletions packages/gotrue/test/custom_http_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:convert';

import 'package:dart_jsonwebtoken/dart_jsonwebtoken.dart';
import 'package:http/http.dart';
import 'package:universal_io/io.dart';

import 'utils.dart';

Expand Down Expand Up @@ -74,7 +73,7 @@ class RetryTestHttpClient extends BaseClient {
Future<StreamedResponse> send(BaseRequest request) async {
retryCount++;
if (retryCount < 4) {
throw SocketException('Retry #$retryCount');
throw ClientException('Retry #$retryCount');
}
final jwt = JWT(
{'exp': (DateTime.now().millisecondsSinceEpoch / 1000).round() + 60},
Expand Down
7 changes: 4 additions & 3 deletions packages/storage_client/lib/src/fetch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import 'package:http_parser/http_parser.dart' show MediaType;
import 'package:mime/mime.dart';
import 'package:retry/retry.dart';
import 'package:storage_client/src/types.dart';
import 'package:universal_io/io.dart';

import 'file_io.dart' if (dart.library.js) './file_stub.dart';

Fetch storageFetch = Fetch();

Expand Down Expand Up @@ -108,7 +109,7 @@ class Fetch {
},
retryIf: (error) =>
retryController?.cancelled != true &&
(error is SocketException || error is TimeoutException),
(error is ClientException || error is TimeoutException),
);

return _handleResponse(streamedResponse, options);
Expand Down Expand Up @@ -152,7 +153,7 @@ class Fetch {
},
retryIf: (error) =>
retryController?.cancelled != true &&
(error is SocketException || error is TimeoutException),
(error is ClientException || error is TimeoutException),
);

return _handleResponse(streamedResponse, options);
Expand Down
1 change: 1 addition & 0 deletions packages/storage_client/lib/src/file_io.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'dart:io' show File;
8 changes: 8 additions & 0 deletions packages/storage_client/lib/src/file_stub.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import 'dart:typed_data';

/// A stub for the `dart:io` [File] class. Only the methods used by the storage client are stubbed.
class File {
String get path => throw UnimplementedError();

Uint8List readAsBytesSync() => throw UnimplementedError();
}
3 changes: 2 additions & 1 deletion packages/storage_client/lib/src/storage_file_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import 'dart:typed_data';

import 'package:storage_client/src/fetch.dart';
import 'package:storage_client/src/types.dart';
import 'package:universal_io/io.dart';

import 'file_io.dart' if (dart.library.js) './file_stub.dart';

class StorageFileApi {
final String url;
Expand Down
1 change: 0 additions & 1 deletion packages/storage_client/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ dependencies:
http: '>=0.13.4 <2.0.0'
http_parser: ^4.0.1
mime: ^1.0.2
universal_io: ^2.0.4
retry: ^3.1.0

dev_dependencies:
Expand Down
3 changes: 1 addition & 2 deletions packages/storage_client/test/custom_http_client.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:convert';

import 'package:http/http.dart';
import 'package:universal_io/io.dart';

class CustomHttpClient extends BaseClient {
@override
Expand All @@ -22,7 +21,7 @@ class RetryHttpClient extends BaseClient {
Future<StreamedResponse> send(BaseRequest request) async {
if (failureCount < 3) {
failureCount++;
throw SocketException('Offline');
throw ClientException('Offline');
}
//Return custom status code to check for usage of this client.
return StreamedResponse(
Expand Down

0 comments on commit 2324228

Please sign in to comment.