From eead562fe2fbf4a5e21299ff3f910594410df7ee Mon Sep 17 00:00:00 2001 From: jld3103 Date: Mon, 10 Apr 2023 14:43:51 +0200 Subject: [PATCH] neon: Retry requests on server errors --- packages/neon/lib/src/utils/request_manager.dart | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/neon/lib/src/utils/request_manager.dart b/packages/neon/lib/src/utils/request_manager.dart index 8feb6bc6..269930f7 100644 --- a/packages/neon/lib/src/utils/request_manager.dart +++ b/packages/neon/lib/src/utils/request_manager.dart @@ -14,6 +14,7 @@ class RequestManager { final Future Function() call, final T Function(R) unwrap, { final bool disableTimeout = false, + final int retries = 0, }) async { if (subject.valueOrNull?.data != null) { subject.add( @@ -53,6 +54,19 @@ class RequestManager { } catch (e, s) { debugPrint(e.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)) { try { subject.add(