Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -343,20 +343,27 @@ public void checkout() {
@Override
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
progressDialog.dismiss();
boolean success = response.isSuccessful();
int statusCode = response.code();
String responseBody = response.body() != null ? response.body().string() : "";
response.close();
if (!success) {

if (statusCode == 422) {
try {
JSONObject errorObj = new JSONObject(responseBody);
final String errorMessage = errorObj.optString("error", "Item is out of stock");
getActivity().runOnUiThread(() -> {
new AlertDialog.Builder(getActivity())
.setTitle("Cannot Complete Purchase")
.setMessage(errorMessage)
.setPositiveButton("OK", null)
.show();
});
} catch (JSONException e) {
handleGenericError(checkoutTransaction);
}
} else if (!response.isSuccessful()) {
Log.d("checkout", "response failed");
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
progressDialog.dismiss();

processDeliveryItem(checkoutTransaction);

checkoutTransaction.finish(SpanStatus.INTERNAL_ERROR);
}
});
handleGenericError(checkoutTransaction);
}
}

Expand Down Expand Up @@ -410,6 +417,19 @@ private JSONObject buildJSONPostData(HashMap<String, StoreItem> selectedStoreIte
return postBody;
}

private void handleGenericError(ITransaction checkoutTransaction) {
getActivity().runOnUiThread(() -> {
progressDialog.dismiss();
new AlertDialog.Builder(getActivity())
.setTitle("Error")
.setMessage("An error occurred processing your order. Please try again.")
.setPositiveButton("OK", null)
.show();
processDeliveryItem(checkoutTransaction);
checkoutTransaction.finish(SpanStatus.INTERNAL_ERROR);
});
}

private void processDeliveryItem(ITransaction checkoutTransaction) {
Log.i("processDeliveryItem", "processDeliveryItem >>>");
ISpan processDeliverySpan = checkoutTransaction.startChild("task", "process delivery");
Expand Down
Loading