fix: improved error handling during scanning phase

This commit is contained in:
antonio 2023-06-24 15:02:13 +02:00
parent e8f2385928
commit 7312ae20d1
3 changed files with 14 additions and 6 deletions

View file

@ -17,8 +17,12 @@ public class ScanRepository {
.enqueue(new Callback<ApiResponse>() {
@Override
public void onResponse(@NonNull Call<ApiResponse> call, @NonNull retrofit2.Response<ApiResponse> response) {
if (response.isSuccessful() && response.body() != null && response.body().getSubsonicResponse().getScanStatus() != null) {
callback.onSuccess(response.body().getSubsonicResponse().getScanStatus().isScanning(), response.body().getSubsonicResponse().getScanStatus().getCount());
if (response.isSuccessful() && response.body() != null && response.body().getSubsonicResponse() != null) {
if (response.body().getSubsonicResponse().getError() != null) {
callback.onError(new Exception(response.body().getSubsonicResponse().getError().getMessage()));
} else if (response.body().getSubsonicResponse().getScanStatus() != null) {
callback.onSuccess(response.body().getSubsonicResponse().getScanStatus().isScanning(), response.body().getSubsonicResponse().getScanStatus().getCount());
}
}
}
@ -36,8 +40,12 @@ public class ScanRepository {
.enqueue(new Callback<ApiResponse>() {
@Override
public void onResponse(@NonNull Call<ApiResponse> call, @NonNull retrofit2.Response<ApiResponse> response) {
if (response.isSuccessful() && response.body() != null && response.body().getSubsonicResponse().getScanStatus() != null) {
callback.onSuccess(response.body().getSubsonicResponse().getScanStatus().isScanning(), response.body().getSubsonicResponse().getScanStatus().getCount());
if (response.isSuccessful() && response.body() != null && response.body().getSubsonicResponse() != null) {
if (response.body().getSubsonicResponse().getError() != null) {
callback.onError(new Exception(response.body().getSubsonicResponse().getError().getMessage()));
} else if (response.body().getSubsonicResponse().getScanStatus() != null) {
callback.onSuccess(response.body().getSubsonicResponse().getScanStatus().isScanning(), response.body().getSubsonicResponse().getScanStatus().getCount());
}
}
}

View file

@ -22,7 +22,7 @@ public class SystemRepository {
public void onResponse(@NonNull Call<ApiResponse> call, @NonNull retrofit2.Response<ApiResponse> response) {
if (response.body() != null) {
if (response.body().getSubsonicResponse().getStatus().equals(ResponseStatus.FAILED)) {
callback.onError(new Exception(response.body().getSubsonicResponse().getError().getCode().getValue() + " - " + response.body().getSubsonicResponse().getError().getMessage()));
callback.onError(new Exception(response.body().getSubsonicResponse().getError().getCode() + " - " + response.body().getSubsonicResponse().getError().getMessage()));
} else if (response.body().getSubsonicResponse().getStatus().equals(ResponseStatus.OK)) {
String password = response.raw().request().url().queryParameter("p");
String token = response.raw().request().url().queryParameter("t");

View file

@ -4,6 +4,6 @@ import androidx.annotation.Keep
@Keep
class Error {
var code: ErrorCode? = null
var code: Int? = null
var message: String? = null
}