Skip to content

Commit 5112bc8

Browse files
Refactor onFailure methods to simplify error handling
Removed userInfo parameter from onFailure methods and related JSON handling.
1 parent 4d7fd83 commit 5112bc8

1 file changed

Lines changed: 3 additions & 37 deletions

File tree

SCGatewayPhonegap.java

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
import java.util.ArrayList;
1515
import android.content.Context;
1616
import android.util.Log;
17-
import android.
18-
widget.Toast;
17+
import android.widget.Toast;
1918

2019
import androidx.annotation.NonNull;
2120
import androidx.annotation.Nullable;
@@ -27,7 +26,6 @@
2726
import com.smallcase.gateway.data.models.InitialisationResponse;
2827
import com.smallcase.gateway.data.listeners.DataListener;
2928
import com.google.gson.Gson;
30-
import com.smallcase.gateway.data.models.UserInfo;
3129
import com.smallcase.gateway.data.models.SmallcaseGatewayDataResponse;
3230
import com.smallcase.gateway.data.listeners.TransactionResponseListener;
3331
import com.smallcase.gateway.data.listeners.MFHoldingsResponseListener;
@@ -251,7 +249,7 @@ public void onSuccess(@NotNull SmallPlugResult smallPlugResult) {
251249
}
252250

253251
@Override
254-
public void onFailure(int i, @NotNull String s, @Nullable String smallcaseAuthToken, @Nullable UserInfo userInfo) {
252+
public void onFailure(int i, @NotNull String s) {
255253

256254
Log.d("SCGatewayPhoneGap", "smallplug onFailure: " + i + s);
257255

@@ -260,22 +258,6 @@ public void onFailure(int i, @NotNull String s, @Nullable String smallcaseAuthTo
260258
jo.put("errorCode", i);
261259
jo.put("errorMessage", s);
262260

263-
JSONObject dataObj = new JSONObject();
264-
if (userInfo != null) {
265-
JSONObject userInfoObj = new JSONObject();
266-
if (userInfo.getNumber() != null) {
267-
userInfoObj.put("number", userInfo.getNumber());
268-
}
269-
if (userInfo.getCountryCode() != null) {
270-
userInfoObj.put("countryCode", userInfo.getCountryCode());
271-
}
272-
dataObj.put("userInfo", userInfoObj);
273-
}
274-
275-
if (dataObj.length() > 0) {
276-
jo.put("data", dataObj);
277-
}
278-
279261
callbackContext.error(jo);
280262
} catch (JSONException e) {
281263
e.printStackTrace();
@@ -329,7 +311,7 @@ public void onSuccess(@NotNull SmallPlugResult smallPlugResult) {
329311
}
330312

331313
@Override
332-
public void onFailure(int i, @NotNull String s, @Nullable String smallcaseAuthToken, @Nullable UserInfo userInfo) {
314+
public void onFailure(int i, @NotNull String s) {
333315

334316
Log.d("SCGatewayPhoneGap", "smallplug onFailure: " + i + s);
335317

@@ -338,22 +320,6 @@ public void onFailure(int i, @NotNull String s, @Nullable String smallcaseAuthTo
338320
jo.put("errorCode", i);
339321
jo.put("errorMessage", s);
340322

341-
JSONObject dataObj = new JSONObject();
342-
if (userInfo != null) {
343-
JSONObject userInfoObj = new JSONObject();
344-
if (userInfo.getNumber() != null) {
345-
userInfoObj.put("number", userInfo.getNumber());
346-
}
347-
if (userInfo.getCountryCode() != null) {
348-
userInfoObj.put("countryCode", userInfo.getCountryCode());
349-
}
350-
dataObj.put("userInfo", userInfoObj);
351-
}
352-
353-
if (dataObj.length() > 0) {
354-
jo.put("data", dataObj);
355-
}
356-
357323
callbackContext.error(jo);
358324
} catch (JSONException e) {
359325
e.printStackTrace();

0 commit comments

Comments
 (0)