From fda494e607b5c8448c35d70b7efd7b93a5b4be4d Mon Sep 17 00:00:00 2001 From: shiwei Date: Tue, 8 Feb 2022 15:06:25 +0800 Subject: [PATCH 1/2] add error handle for product search --- .../visearch/android/network/ProductSearchService.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/visearch-android/src/main/java/com/visenze/visearch/android/network/ProductSearchService.java b/visearch-android/src/main/java/com/visenze/visearch/android/network/ProductSearchService.java index 8e66158..bde7524 100644 --- a/visearch-android/src/main/java/com/visenze/visearch/android/network/ProductSearchService.java +++ b/visearch-android/src/main/java/com/visenze/visearch/android/network/ProductSearchService.java @@ -1,5 +1,6 @@ package com.visenze.visearch.android.network; +import com.google.gson.Gson; import com.visenze.visearch.android.BaseProductSearchParams; import com.visenze.visearch.android.ProductSearchByImageParams; import com.visenze.visearch.android.ProductSearch; @@ -79,11 +80,18 @@ private void handleCallback(Call call, final ProductSearch.Resu call.enqueue(new Callback() { @Override public void onResponse(Call call, Response response) { - if(response.isSuccessful() && response.body() !=null) { ProductResponse data = response.body(); handleResponse(data, resultListener); } else { + if (response.errorBody() != null) { + Gson gson = new Gson(); + ProductResponse resp = gson.fromJson(response.errorBody().charStream(), ProductResponse.class); + if (resp != null && resp.getError()!= null) { + resultListener.onSearchResult(null, resp.getError()); + return; + } + } ErrorData error = new ErrorData(); error.setMessage("api failed"); error.setCode(-1); From 9daa04052a19a3b1a289caf59bc1ac061e9524bc Mon Sep 17 00:00:00 2001 From: shiwei Date: Tue, 8 Feb 2022 15:15:07 +0800 Subject: [PATCH 2/2] update version --- visearch-android/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/visearch-android/build.gradle b/visearch-android/build.gradle index f3ff7ea..f35255b 100644 --- a/visearch-android/build.gradle +++ b/visearch-android/build.gradle @@ -4,8 +4,8 @@ plugins { def versionMajor = 2 def versionMinor = 1 -def versionPatch = 1 -version = '2.1.1' +def versionPatch = 2 +version = '2.1.2' android { compileSdkVersion 29