Flagsmith / flagsmith-flutter-client

Flutter Client for Flagsmith. Ship features with confidence using feature flags and remote config. Host yourself or use our hosted version at https://www.flagsmith.com/
https://www.flagsmith.com/
BSD 3-Clause "New" or "Revised" License
15 stars 15 forks source link

Flagsmith client noisy warning logs in debug mode #67

Open tomwyr opened 1 month ago

tomwyr commented 1 month ago

The current implementation of FlagsmithClient attaches sendTimeout from FlagsmithConfig to every http request it sends. On the web platform, this causes dio client to log warnings about the timeout property being incorrectly set for GET requests:

[πŸ”” Dio] sendTimeout cannot be used without a request body to send
[πŸ”” Dio] _StackTrace (dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 843:28  get current
         dio_web_adapter-2.0.0/lib/src/adapter.dart 149:22                   fetch
         dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54  runBody
         dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 127:5  _async
         dio_web_adapter-2.0.0/lib/src/adapter.dart 31:29                    fetch
         packages/dio/src/dio_mixin.dart 529:27                              _dispatchRequest
         dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50  <fn>
         ...
         )

Consider making FlagsmithClient ignore the timeout property from config for those requests, e.g. by overriding base options for calls with no body:

// flagsmith_client.dart

Options? get _apiGetOptions {
  if (kIsWeb) {
    return Options(sendTimeout: Duration.zero);
  }
  return null;
}

// ...

Future<List<Flag>> _getFlags() async {
    try {
      var response = await _api.get<List<dynamic>>(config.flagsURI, options: _apiGetOptions);
      // ...
}
matthewelwell commented 1 month ago

Thanks for this @tomwyr , if you're willing to submit a PR for this, we'd gratefully receive it!