Browse Source

Merge pull request #114 from jld3103/fix/request-manager-cache

neon: Fix request manager loading from cache
pull/115/head
jld3103 2 years ago committed by GitHub
parent
commit
b924f272c5
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

@ -37,7 +37,11 @@ class RequestManager {
final key = '$clientID-$k';
if (cache != null && await cache!.has(key)) {
yield ResultCached(unwrap(deserialize<R>(json.decode((await cache!.get(key))!))), loading: true);
try {
yield ResultCached(unwrap(deserialize<R>(json.decode((await cache!.get(key))!))), loading: true);
} catch (e) {
debugPrint(e.toString());
}
}
try {
@ -47,8 +51,12 @@ class RequestManager {
} on Exception catch (e) {
if (cache != null && await cache!.has(key)) {
debugPrint(e.toString());
yield ResultCached(unwrap(deserialize<R>(json.decode((await cache!.get(key))!))), error: e);
return;
try {
yield ResultCached(unwrap(deserialize<R>(json.decode((await cache!.get(key))!))), loading: true);
return;
} catch (e) {
debugPrint(e.toString());
}
}
debugPrint(e.toString());
yield Result.error(e);

Loading…
Cancel
Save