ReactiveX / rxdart

The Reactive Extensions for Dart
http://reactivex.io
Apache License 2.0
3.37k stars 270 forks source link

doOnError, doOnData, doOnListen fails if stream results with an error, need an advice how can I fix this. #533

Closed Turbozanik closed 3 years ago

Turbozanik commented 3 years ago

I am trying to make a network request with doOnError, doOnData, doOnListen operators and in my case if request fails, app crashes with the following error. Error: [VERBOSE-2:ui_dart_state.cc(177)] Unhandled Exception: type 'DoStreamTransformer' is not a subtype of type 'StreamTransformer<List, dynamic>' of 'streamTransformer'

0 Stream.transform (dart:async/stream.dart)

1 DoExtensions.doOnListen (package:rxdart/src/transformers/do.dart:294:7)

2 BasePagingController.addLoadingLogic (package:app/presentation/base/pagination/base_paging_controller.dart:13:19)

3 BaseBloc.handlePagingFuture (package:app/presentation/base/base_bloc.dart:50:22)

4 SpotListBlock.refreshSpots (package:app/presentation/pages/spotlist/spot_list_block.dart:28:12)

5 SpotListScreenState.build.. (package:app/presentation/pages/spotlist/spot_list_screen.dart:51:42)

6 RefreshIndicatorState._show. (package:flutter/src/material/refresh_indicator.dart:368:62)

7 _rootRunUnary (dart:async/zone.dart:1198:47)

8 _CustomZone.runUnary (dart:async/zone.dart:11<…>

Code and issue explanation: First step is making request from bloc: Screen Shot 2020-12-03 at 15 07 31 Second step, base error handling wrappers in base bloc: Screen Shot 2020-12-03 at 15 07 46 Third step, handling pages in page controller(doOnError, doOnData, doOnListen are here ot controll pages): Screen Shot 2020-12-03 at 15 08 01 Fourth step is dio error flow showcase: Screen Shot 2020-12-03 at 15 08 34 Fifs step is the place where StreamTransformer<List, dynamic> is comming from: Screen Shot 2020-12-03 at 15 09 36

So, it seems to be all details I have, the question is how can I fix this, and be able to use doOnError, doOnData, doOnListen even if stream fails. PS: I was also trying to place handleError before doOnError etc, but it was still crashing the app..

hoc081098 commented 3 years ago

Trying doOnError((e, s) { }) and checkout version 0.25.0-beta2

Sent from my Redmi 7A using FastHub

Turbozanik commented 3 years ago

Still fails with the same error.

[VERBOSE-2:ui_dart_state.cc(177)] Unhandled Exception: type 'DoStreamTransformer' is not a subtype of type 'StreamTransformer<List, dynamic>' of 'streamTransformer'

0 Stream.transform (dart:async/stream.dart)

1 DoExtensions.doOnError (package:rxdart/src/transformers/do.dart:249:7)

2 BasePagingController.addLoadingLogic (package:app/presentation/base/pagination/base_paging_controller.dart:13:19)

3 BaseBloc.handlePagingFuture (package:app/presentation/base/base_bloc.dart:51:22)

4 SpotListBlock.refreshSpots (package:app/presentation/pages/spotlist/spot_list_block.dart:28:12)

5 SpotListScreenState.build.. (package:app/presentation/pages/spotlist/spot_list_screen.dart:51:42)

6 RefreshIndicatorState._show. (package:flutter/src/material/refresh_indicator.dart:368:62)

7 _rootRunUnary (dart:async/zone.dart:1198:47)

8 _CustomZone.runUnary (dart:async/zone.dart:110<…>

Screen Shot 2020-12-03 at 16 13 02

hoc081098 commented 3 years ago
handlePagingFuture(..., BasePagingController<DataType> pagingController)

instead of

handlePagingFuture(..., BasePagingController pagingController)
Turbozanik commented 3 years ago

Thanks! It works.