Skip to content

Commit

Permalink
Merge pull request #83 from visenze/feature/PS-3189
Browse files Browse the repository at this point in the history
[PS-3189] add error handle for product search
  • Loading branch information
srfication authored Feb 8, 2022
2 parents d662566 + 9daa040 commit 14d7a7a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions visearch-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -79,11 +80,18 @@ private void handleCallback(Call<ProductResponse> call, final ProductSearch.Resu
call.enqueue(new Callback<ProductResponse>() {
@Override
public void onResponse(Call<ProductResponse> call, Response<ProductResponse> 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);
Expand Down

0 comments on commit 14d7a7a

Please sign in to comment.