http_interceptor icon indicating copy to clipboard operation
http_interceptor copied to clipboard

type 'Response' is not a subtype of type 'StreamedResponse' in type cast

Open antonshkurenko opened this issue 2 years ago • 5 comments

Describe the bug Hey guys, I'm using ^2.0.0-beta.7. I have this error in two cases (100% of time):

  1. Any time I use send method in the client (https://pub.dev/documentation/http/latest/http/Client/send.html)
  2. When I provide client to the CacheManager's config here: https://pub.dev/documentation/flutter_cache_manager/latest/flutter_cache_manager/HttpFileService/HttpFileService.html

It looks like it somehow just force casts and crashes every time here: https://github.com/CodingAleCR/http_interceptor/blob/main/lib/http/intercepted_client.dart#L222

Expected behavior No crashes

Please complete the following information):

  • Flutter version: 3.10.5
  • IDE: Android Studio
  • http_interceptor Version: ^2.0.0-beta.7

antonshkurenko avatar Aug 27 '23 13:08 antonshkurenko

I'll have to fork because of this. The Response shouldn't be casted to StreamedResponse specially when the shouldInterceptResponse is set to false.

miguelruivo avatar Jul 08 '24 15:07 miguelruivo

I don't know how I missed this and it has stayed like this so long. Thank you for reporting it and for the subsequent comment that surfaced this. I'll look into it as soon as possible.

PRs are welcomed in any case if you also find a fix for this. 🙏🏻

CodingAleCR avatar Jul 08 '24 19:07 CodingAleCR

So, a bit of an insight for future me:

Your CacheManager uses a HttpFileService that underneath makes use of send. So fixing send should be enough of a fix for both scenarios.

CodingAleCR avatar Jul 10 '24 01:07 CodingAleCR

I got a follow up question for you both @miguelruivo @antonshkurenko, what type of request are you sending into send? I ask because send is expected always to return a StreamedResponse (that's coming from http not something from this library) so I don't think the casting is the issue, that's why I want to make sure things are working properly and your answer would help me figure out things. Either that or a repository where I can replicate the issue would be appreciated.

Another ask is if it's still happening on 2.0.0 stable release. There was a pre-release 2.0.0-beta.8 that never got released and had a fix for this.

CodingAleCR avatar Jul 11 '24 05:07 CodingAleCR

I'll add the PR for reference #132

CodingAleCR avatar Jul 11 '24 06:07 CodingAleCR