diff --git a/android/app/src/main/java/life/nsu/aether/repositories/RefreshRepository.java b/android/app/src/main/java/life/nsu/aether/repositories/RefreshRepository.java index 38be01be..06d1bfd9 100644 --- a/android/app/src/main/java/life/nsu/aether/repositories/RefreshRepository.java +++ b/android/app/src/main/java/life/nsu/aether/repositories/RefreshRepository.java @@ -17,11 +17,14 @@ import org.json.JSONObject; import java.io.IOException; +import java.lang.annotation.Annotation; import life.nsu.aether.utils.networking.NetworkingService; import life.nsu.aether.utils.networking.responses.RefreshResponse; +import okhttp3.ResponseBody; import retrofit2.Call; import retrofit2.Callback; +import retrofit2.Converter; import retrofit2.Response; public class RefreshRepository { @@ -57,19 +60,18 @@ public void onResponse(@NonNull Call call, @NonNull Response converter + = NetworkingService.getInstance().retrofit + .responseBodyConverter(RefreshResponse.class, new Annotation[0]); + RefreshResponse errorResponse = null; try { - JSONObject errorObject = new JSONObject(response.errorBody().string()); - refreshResponseMutableLiveData.postValue(new RefreshResponse(false, "Login first!", "")); - Log.d("refreshResponse", " "+errorObject); - - } catch (JSONException | IOException e) { + errorResponse = converter.convert(response.errorBody()); + refreshResponseMutableLiveData.postValue(errorResponse); + } catch (IOException e) { e.printStackTrace(); } - } } diff --git a/android/app/src/main/java/life/nsu/aether/utils/networking/NetworkingService.java b/android/app/src/main/java/life/nsu/aether/utils/networking/NetworkingService.java index b90c7503..c4528853 100644 --- a/android/app/src/main/java/life/nsu/aether/utils/networking/NetworkingService.java +++ b/android/app/src/main/java/life/nsu/aether/utils/networking/NetworkingService.java @@ -16,7 +16,7 @@ public class NetworkingService { private static NetworkingService mInstance = null; - Retrofit retrofit; + public Retrofit retrofit; public static synchronized NetworkingService getInstance() { if (mInstance == null) {