Skip to content

Commit 9eef4a4

Browse files
Remove status code obfuscation (#1255)
1 parent 57f91ea commit 9eef4a4

File tree

5 files changed

+20
-16
lines changed

5 files changed

+20
-16
lines changed

Branch-SDK/src/main/java/io/branch/referral/BranchError.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,14 @@ private String initErrorCodeAndGetLocalisedMessage(int statusCode) {
131131
errMsg = " Session initialization already happened. To force a new session, " +
132132
"set intent extra, \"branch_force_new_session\", to true.";
133133
} else if (statusCode >= 500 || statusCode == ERR_BRANCH_UNABLE_TO_REACH_SERVERS) {
134-
errorCode_ = ERR_BRANCH_UNABLE_TO_REACH_SERVERS;
134+
errorCode_ = statusCode;
135135
errMsg = " Unable to reach the Branch servers, please try again shortly.";
136136
} else if (statusCode == 409 || statusCode == ERR_BRANCH_RESOURCE_CONFLICT) {
137-
errorCode_ = ERR_BRANCH_RESOURCE_CONFLICT;
137+
errorCode_ = statusCode;
138138
errMsg = " A resource with this identifier already exists.";
139139
} else if (statusCode >= 400 || statusCode == ERR_BRANCH_INVALID_REQUEST) {
140-
errorCode_ = ERR_BRANCH_INVALID_REQUEST;
141-
errMsg = " The request was invalid.";
140+
errorCode_ = statusCode;
141+
errMsg = " The request was invalid";
142142
} else if (statusCode == ERR_IMPROPER_REINITIALIZATION) {
143143
errorCode_ = ERR_IMPROPER_REINITIALIZATION;
144144
errMsg = "Intra-app linking (i.e. session reinitialization) requires an intent flag, \"branch_force_new_session\".";

Branch-SDK/src/main/java/io/branch/referral/ServerRequestQueue.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,11 @@ static void shutDown() {
8181
*/
8282
@SuppressLint("CommitPrefEdits")
8383
private ServerRequestQueue(Context c) {
84+
BranchLogger.v("Creating ServerRequestQueue " + c);
8485
sharedPref = c.getSharedPreferences("BNC_Server_Request_Queue", Context.MODE_PRIVATE);
8586
editor = sharedPref.edit();
8687
queue = Collections.synchronizedList(new LinkedList<ServerRequest>());
88+
BranchLogger.v("Created queue " + queue);
8789
}
8890

8991
/**
@@ -321,12 +323,12 @@ void processNextQueueItem(String callingMethodName) {
321323
if (!(req instanceof ServerRequestRegisterInstall) && !hasUser()) {
322324
BranchLogger.d("Branch Error: User session has not been initialized!");
323325
networkCount_ = 0;
324-
req.handleFailure(BranchError.ERR_NO_SESSION, "");
326+
req.handleFailure(BranchError.ERR_NO_SESSION, "Request " + req + " has no session.");
325327
}
326328
// Determine if a session is needed to execute (SDK-271)
327329
else if (requestNeedsSession(req) && !isSessionAvailableForRequest()) {
328330
networkCount_ = 0;
329-
req.handleFailure(BranchError.ERR_NO_SESSION, "");
331+
req.handleFailure(BranchError.ERR_NO_SESSION, "Request " + req + " has no session.");
330332
} else {
331333
executeTimedBranchPostTask(req, Branch.getInstance().prefHelper_.getTaskTimeout());
332334
}
@@ -434,7 +436,7 @@ private void awaitTimedBranchPostTask(CountDownLatch latch, int timeout, BranchP
434436
try {
435437
if (!latch.await(timeout, TimeUnit.MILLISECONDS)) {
436438
postTask.cancel(true);
437-
postTask.onPostExecuteInner(new ServerResponse(postTask.thisReq_.getRequestPath(), ERR_BRANCH_TASK_TIMEOUT, "", ""));
439+
postTask.onPostExecuteInner(new ServerResponse(postTask.thisReq_.getRequestPath(), ERR_BRANCH_TASK_TIMEOUT, "", "Thread task timed out. Timeout: " + timeout));
438440
}
439441
} catch (InterruptedException e) {
440442
BranchLogger.e("Caught InterruptedException " + e.getMessage());
@@ -455,8 +457,9 @@ public void handleNewRequest(ServerRequest req) {
455457
BranchLogger.d("handleNewRequest " + req);
456458
// If Tracking is disabled fail all messages with ERR_BRANCH_TRACKING_DISABLED
457459
if (Branch.getInstance().getTrackingController().isTrackingDisabled() && !req.prepareExecuteWithoutTracking()) {
458-
BranchLogger.d("Requested operation cannot be completed since tracking is disabled [" + req.requestPath_.getPath() + "]");
459-
req.handleFailure(BranchError.ERR_BRANCH_TRACKING_DISABLED, "");
460+
String errMsg = "Requested operation cannot be completed since tracking is disabled [" + req.requestPath_.getPath() + "]";
461+
BranchLogger.d(errMsg);
462+
req.handleFailure(BranchError.ERR_BRANCH_TRACKING_DISABLED, errMsg);
460463
return;
461464
}
462465
//If not initialised put an open or install request in front of this request(only if this needs session)
@@ -514,7 +517,7 @@ protected ServerResponse doInBackground(Void... voids) {
514517
// update queue wait time
515518
thisReq_.doFinalUpdateOnBackgroundThread();
516519
if (Branch.getInstance().getTrackingController().isTrackingDisabled() && !thisReq_.prepareExecuteWithoutTracking()) {
517-
return new ServerResponse(thisReq_.getRequestPath(), BranchError.ERR_BRANCH_TRACKING_DISABLED, "", "");
520+
return new ServerResponse(thisReq_.getRequestPath(), BranchError.ERR_BRANCH_TRACKING_DISABLED, "", "Tracking is disabled");
518521
}
519522
String branchKey = Branch.getInstance().prefHelper_.getBranchKey();
520523
ServerResponse result = null;
@@ -662,7 +665,7 @@ void onRequestFailed(ServerResponse serverResponse, int status) {
662665
//On Network error or Branch is down fail all the pending requests in the queue except
663666
//for request which need to be replayed on failure.
664667
ServerRequestQueue.this.networkCount_ = 0;
665-
thisReq_.handleFailure(status, serverResponse.getFailReason() + " " + serverResponse.getMessage());
668+
thisReq_.handleFailure(status, serverResponse.getFailReason() + status + " " + serverResponse.getMessage());
666669
}
667670

668671
boolean unretryableErrorCode = (400 <= status && status <= 451) || status == BranchError.ERR_BRANCH_TRACKING_DISABLED;

Branch-SDK/src/main/java/io/branch/referral/ServerRequestRegisterInstall.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public void handleFailure(int statusCode, String causeMsg) {
120120
} catch (JSONException ex) {
121121
BranchLogger.w("Caught JSONException " + ex.getMessage());
122122
}
123-
callback_.onInitFinished(obj, new BranchError("Trouble initializing Branch. " + causeMsg, statusCode));
123+
callback_.onInitFinished(obj, new BranchError("Trouble initializing Branch. " + this + " failed. " + causeMsg, statusCode));
124124
}
125125
}
126126

Branch-SDK/src/main/java/io/branch/referral/ServerRequestRegisterOpen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void handleFailure(int statusCode, String causeMsg) {
9393
} catch (JSONException ex) {
9494
BranchLogger.w("Caught JSONException " + ex.getMessage());
9595
}
96-
callback_.onInitFinished(obj, new BranchError("Trouble initializing Branch. " + causeMsg, statusCode));
96+
callback_.onInitFinished(obj, new BranchError("Trouble initializing Branch. " + this + " failed. " + causeMsg, statusCode));
9797
}
9898
}
9999

Branch-SDK/src/main/java/io/branch/referral/network/BranchRemoteInterface.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public final ServerResponse make_restful_get(String url, JSONObject params, Stri
9494
if (addCommonParams(params, branchKey)) {
9595
modifiedUrl += this.convertJSONtoString(params);
9696
} else {
97-
return new ServerResponse(tag, BranchError.ERR_BRANCH_KEY_INVALID, "", "");
97+
return new ServerResponse(tag, BranchError.ERR_BRANCH_KEY_INVALID, "", "Invalid key");
9898
}
9999

100100
long reqStartTime = System.currentTimeMillis();
@@ -128,7 +128,7 @@ public final ServerResponse make_restful_post(JSONObject body, String url, Strin
128128
body = body != null ? body : new JSONObject();
129129

130130
if (!addCommonParams(body, branchKey)) {
131-
return new ServerResponse(tag, BranchError.ERR_BRANCH_KEY_INVALID, "", "");
131+
return new ServerResponse(tag, BranchError.ERR_BRANCH_KEY_INVALID, "", "Failed to set common parameters, body: " + body + " key: " + branchKey);
132132
}
133133
BranchLogger.v("posting to " + url);
134134
BranchLogger.v("Post value = " + body.toString());
@@ -137,7 +137,7 @@ public final ServerResponse make_restful_post(JSONObject body, String url, Strin
137137
BranchResponse response = doRestfulPost(url, body);
138138
return processEntityForJSON(response, tag, response.requestId);
139139
} catch (BranchRemoteException branchError) {
140-
return new ServerResponse(tag, branchError.branchErrorCode, "", branchError.branchErrorMessage);
140+
return new ServerResponse(tag, branchError.branchErrorCode, "", "Failed network request. " + branchError.branchErrorMessage);
141141
} finally {
142142
if (Branch.getInstance() != null) {
143143
int brttVal = (int) (System.currentTimeMillis() - reqStartTime);
@@ -201,6 +201,7 @@ private ServerResponse processEntityForJSON(BranchResponse response, String tag,
201201
}
202202

203203
private boolean addCommonParams(JSONObject post, String branch_key) {
204+
BranchLogger.v("addCommonParams post: " + post + " key: " + branch_key);
204205
try {
205206
if (!post.has(Defines.Jsonkey.UserData.getKey())) { // user data already has the sdk in it as part of v2 request
206207
post.put(Defines.Jsonkey.SDK.getKey(), "android" + Branch.getSdkVersionNumber());

0 commit comments

Comments
 (0)