Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError Occurs When Map Data and Headers are Set Together #173

Open
cizmarf opened this issue Jun 15, 2024 · 0 comments
Open

TypeError Occurs When Map Data and Headers are Set Together #173

cizmarf opened this issue Jun 15, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@cizmarf
Copy link

cizmarf commented Jun 15, 2024

Description

If Map response data and headers are set together it throws the exception
Error: TypeError: Instance of 'IdentityMap<String, String>': type 'IdentityMap<String, String>' is not a subtype of type 'String'.

Steps to reproduce

  1. Define mocked route
  dioAdapter.onGet(
    'https://example.com/user/john',
    (server) => server.reply(
      200,
      {
        'name': 'John',
        'surname': 'Doe',
      },
      headers: {
        'set-cookie': ['a', 'b']
      },
      delay: const Duration(seconds: 1),
    ),
  );
  1. Call the endpoint
Response response = await dio.get(
      'https://example.com/user/john',
    );
  1. Catch the exception

Expected behavior

print(response.data); should print {name: John, surname: Doe}.

Screenshots

No screenshots

System details

flutter doctor

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.22.0, on macOS 14.3 23D5033f darwin-arm64 (Rosetta), locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.2)
[✓] VS Code (version 1.90.0)
[✓] Connected device (4 available)
    ! Error: Browsing on the local area network for Filip‘s iPad. Ensure the device is unlocked and attached with a cable or associated with the
      same local area network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)
[✓] Network resources

• No issues found!

pubspec.yaml

environment:
  sdk: '>=3.4.0 <4.0.0'

dependencies:
  dio: ^5.4.3+1
  flutter:
    sdk: flutter
  http_mock_adapter: ^0.6.1

Additional context

Here is the minimal not working app.
https://github.com/cizmarf/HttpMockAdapterBugReport/blob/main/lib/main.dart

Its output is:

Fetching Foo, Map body without headers works
{name: Foo, surname: Bar}
Fetching Foo finished

Fetching Jane, String body with headers works
{
        'name': 'Jane',
        'surname': 'Doe',
      }
Fetching Jane finished

Fetching John, Map body with headers DOES NOT work
ERROR HAPPENS HERE
DioException [unknown]: null
Error: TypeError: Instance of 'IdentityMap<String, String>': type 'IdentityMap<String, String>' is not a subtype of type 'String'
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 296:3  throw_
packages/dio/src/dio_mixin.dart 509:7                                        fetch
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 60:31           <fn>
dart-sdk/lib/async/zone.dart 1666:54                                         runBinary
dart-sdk/lib/async/future_impl.dart 178:22                                   handleError
dart-sdk/lib/async/future_impl.dart 859:46                                   handleError
dart-sdk/lib/async/future_impl.dart 880:13                                   _propagateToListeners
dart-sdk/lib/async/future_impl.dart 660:5                                    [_completeError]
dart-sdk/lib/async/future_impl.dart 746:7                                    callback
dart-sdk/lib/async/schedule_microtask.dart 40:11                             _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5                              _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 181:7           <fn>

Fetching John finished
@cizmarf cizmarf added the bug Something isn't working label Jun 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant