From c440c0d67ab287e59b3516735547076cfd871f2e Mon Sep 17 00:00:00 2001 From: Denys Podymskyy Date: Thu, 16 Jul 2020 17:03:22 +0300 Subject: [PATCH] Added retrying in case of any netowrk errors (except HTTP exceptions) --- .../getbubblenow/android/repository/DataRepository.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ui/src/main/java/com/getbubblenow/android/repository/DataRepository.java b/ui/src/main/java/com/getbubblenow/android/repository/DataRepository.java index e7d8ae8..f8778b7 100644 --- a/ui/src/main/java/com/getbubblenow/android/repository/DataRepository.java +++ b/ui/src/main/java/com/getbubblenow/android/repository/DataRepository.java @@ -171,6 +171,7 @@ public class DataRepository { Disposable getNodeBaseURIDisposable = clientApi.getNodeBaseURI(header) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) + .retry((attempts, error) -> attempts < 5 && error instanceof IOException) .subscribe(networks -> { for (Network network : networks) { if (network.getState().equals(RUNNING)) { @@ -191,6 +192,7 @@ public class DataRepository { Disposable getNetworkStateDisposable = clientApi.getNetworkState(UserStore.getInstance(context).getUsername(), network.getUuid(), header) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) + .retry((attempts, error) -> attempts < 5 && error instanceof IOException) .subscribe(networkStatus -> { int indexNetworkState = 0; for (int i = 0; i < networkStatus.size(); i++) { @@ -210,6 +212,7 @@ public class DataRepository { Disposable getNodeBaseURIDisposable = clientApi.getNodeBaseURI(header) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) + .retry((attempts, error) -> attempts < 5 && error instanceof IOException) .subscribe(networks -> { for (Network network : networks) { if (network.getState().equals(RUNNING)) { @@ -278,6 +281,7 @@ public class DataRepository { Disposable disposableLogin = clientApi.login(data) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) + .retry((attempts, error) -> attempts < 5 && error instanceof IOException) .subscribe(user -> { UserStore.getInstance(context).setToken(user.getToken()); if (!isDeviceLoggedIn(context)) { @@ -297,6 +301,7 @@ public class DataRepository { Disposable disposableAllDevices = clientApi.getAllDevices(header) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) + .retry((attempts, error) -> attempts < 5 && error instanceof IOException) .subscribe(listDevices -> { boolean hasDevice = false; for (Device item : listDevices) { @@ -329,6 +334,7 @@ public class DataRepository { final Disposable disposableAllDevices = clientApi.getAllDevices(header) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) + .retry((attempts, error) -> attempts < 5 && error instanceof IOException) .subscribe(listDevices -> { String brandModel = brand + SPACE + model + SPACE; final List list = listDevices; @@ -377,6 +383,7 @@ public class DataRepository { final Disposable disposableAddDevice = clientApi.addDevice(header, body) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) + .retry((attempts, error) -> attempts < 5 && error instanceof IOException) .subscribe(device -> { deviceID = device.getUuid(); getCertificate(context).observe((LifecycleOwner) context, new Observer>() { @@ -430,6 +437,7 @@ public class DataRepository { Disposable disposableAddDevice = clientApi.addDevice(header, body) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) + .retry((attempts, error) -> attempts < 5 && error instanceof IOException) .subscribe(device -> { DataRepository.deviceName = device.getName(); DataRepository.deviceID = device.getUuid(); @@ -627,6 +635,7 @@ public class DataRepository { final Disposable certificateDisposable = clientApi.getCertificate() .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) + .retry((attempts, error) -> attempts < 5 && error instanceof IOException) .subscribe(certificate -> { final InputStream inputStream = certificate.byteStream(); final Scanner scanner = new Scanner(inputStream).useDelimiter(DELIMITER);