1

Infrequently I get Connection reset by peer error. As a result the the application continues to see circular progress bar and remains stuck there.

I am using http package "http: ^0.13.5".

Is there a way to handle this exception?

[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: Connection reset by peer
#0      IOClient.send
io_client.dart:90
<asynchronous suspension>
#1      BaseClient._sendUnstreamed
base_client.dart:93
<asynchronous suspension>
#2      _withClient
http.dart:164
<asynchronous suspension>
#3      _MainViewPageState.getRideInfo
main_view.dart:107
<asynchronous suspension>
Saad Bashir
  • 4,341
  • 8
  • 30
  • 60

1 Answers1

0

Let's say that you assigned a bool value to check wether loading or not, so try to assign another one to check if there an error or not.
Try to do like this

// init hasError and isLoading
hasError = false;
isLoading = false;
try{
  //assign isLoading value
  isLoading = true;
  
  //make you http connection
}
catch (e){
  //assign hasError value
  hasError = true;
  isLoading = false;
}  

now check if(hasError) then show something to tell the user that something went wrong.

Ahmad Hasan
  • 101
  • 5