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

DioError [unknown] If the server returns an illegal json #1749

Closed
simonkimi opened this issue Mar 19, 2023 · 1 comment
Closed

DioError [unknown] If the server returns an illegal json #1749

simonkimi opened this issue Mar 19, 2023 · 1 comment
Labels
i: wontfix This will not be worked on

Comments

@simonkimi
Copy link

simonkimi commented Mar 19, 2023

Package

dio

Version

5.0.3

Output of flutter doctor -v

[✓] Flutter (Channel stable, 3.7.7, on Microsoft Windows [Version 10.0.22621.1413], locale zh-CN)
    • Flutter version 3.7.7 on channel stable at E:\sdk\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2ad6cd72c0 (11 days ago), 2023-03-08 09:41:59 -0800
    • Engine revision 1837b5be5f
    • Dart version 2.19.4
    • DevTools version 2.20.1
    • Pub download mirror https://pub.flutter-io.cn
    • Flutter download mirror https://storage.flutter-io.cn

[✓] Windows Version (Installed version of Windows is version 10 or higher)

Dart Version

2.19.4

Steps to Reproduce

import 'package:dio/dio.dart';

void main() async {
  var dio = Dio();
  final rsp = await dio.get('https://httpbin.org/stream/2');
  print(rsp.data);
}

Expected Result

Returns 200, but with an illegal json.
Because the server returned 200 ok, this request should be completed.
Error handling should be my own responsibility.

{"url": "https://httpbin.org/stream/2", "args": {}, "headers": {"Host": "httpbin.org", "X-Amzn-Trace-Id": "Root=1-64170988-2bab114271cd89057b8db564", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/112.0", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8", "Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2", "Accept-Encoding": "gzip, deflate, br", "Dnt": "1", "Upgrade-Insecure-Requests": "1", "Sec-Fetch-Dest": "document", "Sec-Fetch-Mode": "navigate", "Sec-Fetch-Site": "none", "Sec-Fetch-User": "?1"}, "origin": "46.232.120.163", "id": 0}
{"url": "https://httpbin.org/stream/2", "args": {}, "headers": {"Host": "httpbin.org", "X-Amzn-Trace-Id": "Root=1-64170988-2bab114271cd89057b8db564", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/112.0", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8", "Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2", "Accept-Encoding": "gzip, deflate, br", "Dnt": "1", "Upgrade-Insecure-Requests": "1", "Sec-Fetch-Dest": "document", "Sec-Fetch-Mode": "navigate", "Sec-Fetch-Site": "none", "Sec-Fetch-User": "?1"}, "origin": "46.232.120.163", "id": 1}

Actual Result

Unhandled exception:
DioError [unknown]: null
Error: FormatException: Unexpected character (at line 2, character 1)
{"url": "https://httpbin.org/stream/2", "args": {}, "headers": {"Host": "ht...
^

#0      DioMixin.fetch.<anonymous closure> (package:dio/src/dio_mixin.dart:538:7)
#1      _RootZone.runBinary (dart:async/zone.dart:1665:54)
#2      _FutureListener.handleError (dart:async/future_impl.dart:162:22)
#3      Future._propagateToListeners.handleError (dart:async/future_impl.dart:779:47)
#4      Future._propagateToListeners (dart:async/future_impl.dart:800:13)
#5      Future._completeError (dart:async/future_impl.dart:575:5)
#6      _SyncCompleter._completeError (dart:async/future_impl.dart:51:12)
#7      _Completer.completeError (dart:async/future_impl.dart:23:5)
@simonkimi simonkimi added h: need triage This issue needs to be categorized s: bug Something isn't working labels Mar 19, 2023
@AlexV525
Copy link
Member

This is because the default ResponseType is .json. Set .plain if you don't want to imply any transforms.

@AlexV525 AlexV525 closed this as not planned Won't fix, can't repro, duplicate, stale Mar 19, 2023
@AlexV525 AlexV525 added i: wontfix This will not be worked on and removed h: need triage This issue needs to be categorized s: bug Something isn't working labels Jun 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
i: wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants