handle rpc exceptions

master
fuwa 5 years ago
parent c90ac5cc38
commit 4d4b06c14a

@ -30,9 +30,11 @@ Future<http.Response> rpc(String method) async {
if (kReleaseMode) {
url = 'http://127.0.0.1:34568/json_rpc';
} else {
url = 'http://192.168.10.100:34568/json_rpc';
url = 'http://192.168.10.101:34568/json_rpc';
}
url = 'http://127.0.0.1:34568/json_rpc';
final body = json.encode
(
{
@ -42,10 +44,16 @@ Future<http.Response> rpc(String method) async {
}
);
var response = await http.post
( url,
body: body
);
var response;
try {
response = await http.post
( url,
body: body
);
}
catch (e) {
print(e);
}
return response;
}
@ -57,6 +65,8 @@ Future<http.Response> syncInfo() async {
Future<int> targetHeight() async {
var response = await syncInfo();
if (response == null) return -1;
// print('Response status: ${response.statusCode}');
if (response.statusCode != 200) {
return -1;
@ -69,6 +79,8 @@ Future<int> targetHeight() async {
Future<int> height() async {
var response = await syncInfo();
if (response == null) return -1;
// print('Response status: ${response.statusCode}');
if (response.statusCode != 200) {
return -1;

@ -171,7 +171,7 @@ class SyncedState extends HookedState {
while (true) {
final _targetHeight = await rpc.targetHeight();
if (_targetHeight != 0) break;
if (_targetHeight > 0) break;
height = await rpc.height();
await Future.delayed(const Duration(seconds: 2), () => "1");

Loading…
Cancel
Save