Ignore 404 when trying to update draft comment on sign-in

Unsubmitted comments are saved to the cookie storage when signed out
so that they can be recalled upon next sign-in. If on next sign-in a
draft comment should be updated, that was deleted in the meantime, the
request to update the draft comment fails with '404 Not Found'. This
results in displaying the following error to the user.

  "Code Review - Error
  The page you requested was not found, or you do not have permission
  to view this page."

Since the comment was not removed from the cookie storage, the user
got the same failure on next sign-in again.

Since the comment was deleted it is safe to ignore these failures and
to remove the inapplicable unsubmitted comment from the cookie
storage.

Change-Id: Ibab2abb7d8cd340f5d3df239d77d85c37447b249
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2016-07-13 13:10:45 +02:00
parent d46a8cdd65
commit 7100814be0

View File

@@ -18,6 +18,7 @@ import com.google.gerrit.client.changes.CommentApi;
import com.google.gerrit.client.changes.CommentInfo;
import com.google.gerrit.client.diff.CommentRange;
import com.google.gerrit.client.rpc.GerritCallback;
import com.google.gerrit.client.rpc.RestApi;
import com.google.gerrit.extensions.client.Side;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet;
@@ -126,18 +127,34 @@ public class LocalComments {
final StorageBackend storage = new StorageBackend();
for (final String cookie : storage.getKeys()) {
if (isInlineComment(cookie)) {
GerritCallback<CommentInfo> cb = new GerritCallback<CommentInfo>() {
InlineComment input = getInlineComment(cookie);
if (input.commentInfo.id() == null) {
CommentApi.createDraft(input.psId, input.commentInfo,
new GerritCallback<CommentInfo>() {
@Override
public void onSuccess(CommentInfo result) {
storage.removeItem(cookie);
}
};
InlineComment input = getInlineComment(cookie);
if (input.commentInfo.id() == null) {
CommentApi.createDraft(input.psId, input.commentInfo, cb);
});
} else {
CommentApi.updateDraft(input.psId, input.commentInfo.id(),
input.commentInfo, cb);
input.commentInfo, new GerritCallback<CommentInfo>() {
@Override
public void onSuccess(CommentInfo result) {
storage.removeItem(cookie);
}
@Override
public void onFailure(Throwable caught) {
if (RestApi.isNotFound(caught)) {
// the draft comment, that was supposed to be updated,
// was deleted in the meantime
storage.removeItem(cookie);
} else {
super.onFailure(caught);
}
}
});
}
}
}