Browse Source

Merge pull request #242 from provokateurin/feature/retry-requests

neon: Retry requests on server errors
pull/244/head
Kate 2 years ago committed by GitHub
parent
commit
a4f5070f42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      packages/neon/lib/src/utils/request_manager.dart

14
packages/neon/lib/src/utils/request_manager.dart

@ -14,6 +14,7 @@ class RequestManager {
final Future<R> Function() call, final Future<R> Function() call,
final T Function(R) unwrap, { final T Function(R) unwrap, {
final bool disableTimeout = false, final bool disableTimeout = false,
final int retries = 0,
}) async { }) async {
if (subject.valueOrNull?.data != null) { if (subject.valueOrNull?.data != null) {
subject.add( subject.add(
@ -53,6 +54,19 @@ class RequestManager {
} catch (e, s) { } catch (e, s) {
debugPrint(e.toString()); debugPrint(e.toString());
debugPrint(s.toString()); debugPrint(s.toString());
if (e is NextcloudApiException && e.statusCode >= 500 && retries < 3) {
debugPrint('Retrying...');
await wrapNextcloud(
clientID,
k,
subject,
call,
unwrap,
disableTimeout: disableTimeout,
retries: retries + 1,
);
return;
}
if (cache != null && await cache!.has(key)) { if (cache != null && await cache!.has(key)) {
try { try {
subject.add( subject.add(

Loading…
Cancel
Save