Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

Commit

Permalink
feat: implmented retry for general api requests
Browse files Browse the repository at this point in the history
  • Loading branch information
SlayerOrnstein committed May 12, 2021
1 parent 670e68f commit 9607c71
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions lib/wfcd_client.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:http/http.dart' as http;
import 'package:retry/retry.dart';
import 'package:wfcd_client/src/exceptions.dart';

import 'entities.dart';
Expand Down Expand Up @@ -91,15 +94,19 @@ class WarframestatClient {
final headers = <String, String>{'Accept-Language': language.asString};

try {
final response = await _client.get(
Uri.parse('$_endpoint/$path'),
headers: headers,
return retry(
() async {
final res = await _client
.get(Uri.parse('$_endpoint/$path'), headers: headers)
.timeout(const Duration(seconds: 5));

return json.decode(res.body) as T;
},
retryIf: (e) =>
e is SocketException ||
e is TimeoutException ||
e is FormatException,
);

if (response.statusCode != 200)
throw ServerException(response.statusCode, response.body);

return json.decode(response.body) as T;
} catch (e) {
return null;
}
Expand Down

0 comments on commit 9607c71

Please sign in to comment.