Browse Source

neon: Retry requests on server errors

pull/242/head
jld3103 2 years ago
parent
commit
eead562fe2
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  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