-
Couldn't load subscription status.
- Fork 46
Fix posting navigation: handle successful responses in error handler #154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f32c1a7
ad02495
9474165
cb7bc17
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -134,26 +134,49 @@ public void handleError(GeneralError generalError) { | |||||||
| if (Check.isEmpty(response)) return; | ||||||||
| Observable.just(response) | ||||||||
| .compose(rx(null)) | ||||||||
| .map(s -> APIService.fruit().fromHtml(s, AppendTopicPageInfo.class)) | ||||||||
| .subscribe(new GeneralConsumer<AppendTopicPageInfo>() { | ||||||||
| .map(s -> { | ||||||||
| // First, check if this is actually a successful append | ||||||||
| // (V2EX may return the topic page on success, which triggers error handler due to redirects) | ||||||||
| TopicInfo topicInfo = APIService.fruit().fromHtml(s, TopicInfo.class); | ||||||||
| if (isSuccessfulTopicResponse(topicInfo)) { | ||||||||
| return topicInfo; | ||||||||
| } | ||||||||
| // If not a valid topic, try parsing as error page | ||||||||
| return APIService.fruit().fromHtml(s, AppendTopicPageInfo.class); | ||||||||
| }) | ||||||||
| .subscribe(new GeneralConsumer<BaseInfo>() { | ||||||||
| @Override | ||||||||
| public void onConsume(AppendTopicPageInfo pageInfo) { | ||||||||
| AppendTopicPageInfo.Problem problem = pageInfo.getProblem(); | ||||||||
| if (problem != null) { | ||||||||
| StringBuilder msg = new StringBuilder(); | ||||||||
| for (int i = 0; i < problem.getTips().size(); i++) { | ||||||||
| msg.append(i + 1).append(". ").append(problem.getTips().get(i)).append("\n"); | ||||||||
| public void onConsume(BaseInfo baseInfo) { | ||||||||
| if (baseInfo instanceof TopicInfo) { | ||||||||
| // Actually a success! Treat it as such | ||||||||
| onAfterAppendTopic((TopicInfo) baseInfo); | ||||||||
| } else if (baseInfo instanceof AppendTopicPageInfo) { | ||||||||
| AppendTopicPageInfo pageInfo = (AppendTopicPageInfo) baseInfo; | ||||||||
|
Comment on lines
+153
to
+154
|
||||||||
| } else if (baseInfo instanceof AppendTopicPageInfo) { | |
| AppendTopicPageInfo pageInfo = (AppendTopicPageInfo) baseInfo; | |
| } else if (baseInfo instanceof AppendTopicPageInfo pageInfo) { |
Copilot
AI
Oct 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicated success-detection logic; refactor into a shared helper to centralize the definition of a 'successful' TopicInfo response.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -203,6 +203,13 @@ public void handleError(GeneralError generalError) { | |||||||||||||||||||||||||||||
| Observable.just(response) | ||||||||||||||||||||||||||||||
| .compose(rx(null)) | ||||||||||||||||||||||||||||||
| .map(s -> { | ||||||||||||||||||||||||||||||
| // First, check if this is actually a successful topic creation | ||||||||||||||||||||||||||||||
| // (V2EX may return the topic page on success, which triggers error handler due to redirects) | ||||||||||||||||||||||||||||||
| TopicInfo topicInfo = APIService.fruit().fromHtml(s, TopicInfo.class); | ||||||||||||||||||||||||||||||
| if (isSuccessfulTopicResponse(topicInfo)) { | ||||||||||||||||||||||||||||||
| return topicInfo; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| // If not a valid topic, try parsing as error pages | ||||||||||||||||||||||||||||||
|
Comment on lines
+206
to
+212
|
||||||||||||||||||||||||||||||
| BaseInfo resultInfo = APIService.fruit().fromHtml(s, CreateTopicPageInfo.class); | ||||||||||||||||||||||||||||||
| if (!resultInfo.isValid()) { | ||||||||||||||||||||||||||||||
| resultInfo = APIService.fruit().fromHtml(s, NewUserBannedCreateInfo.class); | ||||||||||||||||||||||||||||||
|
|
@@ -212,7 +219,10 @@ public void handleError(GeneralError generalError) { | |||||||||||||||||||||||||||||
| .subscribe(new GeneralConsumer<BaseInfo>(this) { | ||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||
| public void onConsume(BaseInfo baseInfo) { | ||||||||||||||||||||||||||||||
| if (baseInfo instanceof CreateTopicPageInfo) { | ||||||||||||||||||||||||||||||
| if (baseInfo instanceof TopicInfo) { | ||||||||||||||||||||||||||||||
| // Actually a success! Treat it as such | ||||||||||||||||||||||||||||||
| onPostSuccess((TopicInfo) baseInfo); | ||||||||||||||||||||||||||||||
| } else if (baseInfo instanceof CreateTopicPageInfo) { | ||||||||||||||||||||||||||||||
| onPostFailure((CreateTopicPageInfo) baseInfo); | ||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||
| onBannedCreateTopic((NewUserBannedCreateInfo) baseInfo); | ||||||||||||||||||||||||||||||
|
Comment on lines
+222
to
228
|
||||||||||||||||||||||||||||||
| if (baseInfo instanceof TopicInfo) { | |
| // Actually a success! Treat it as such | |
| onPostSuccess((TopicInfo) baseInfo); | |
| } else if (baseInfo instanceof CreateTopicPageInfo) { | |
| onPostFailure((CreateTopicPageInfo) baseInfo); | |
| } else { | |
| onBannedCreateTopic((NewUserBannedCreateInfo) baseInfo); | |
| if (baseInfo instanceof TopicInfo topicInfo) { | |
| // Actually a success! Treat it as such | |
| onPostSuccess(topicInfo); | |
| } else if (baseInfo instanceof CreateTopicPageInfo createTopicPageInfo) { | |
| onPostFailure(createTopicPageInfo); | |
| } else if (baseInfo instanceof NewUserBannedCreateInfo bannedCreateInfo) { | |
| onBannedCreateTopic(bannedCreateInfo); |
Copilot
AI
Oct 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This helper method is duplicated in AppendTopicActivity; consider extracting it to a shared utility (e.g., TopicResponseUtils) or a base activity to avoid divergence if success criteria evolve.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The append flow now treats a TopicInfo parsed in the error path as success; add a test that feeds redirected topic HTML to confirm onAfterAppendTopic() is invoked and no error dialog appears.