Skip to content

A platform for community discussion. Free, open, simple.

FIX: Re-throw non-403 errors in loadIntoIdentityMap (#37521)

Sam0a060f5063e2
diff --git a/frontend/discourse/app/controllers/topic.js b/frontend/discourse/app/controllers/topic.js
index 148df69eb75..3d9e895a14e 100644
--- a/frontend/discourse/app/controllers/topic.js
+++ b/frontend/discourse/app/controllers/topic.js
@@ -671,30 +671,28 @@ export default class TopicController extends Controller {
}
@action
- cancelFilter(nearestPost = null) {
- const postStream = this.get("model.postStream");
+ async cancelFilter(nearestPost = null) {
+ const postStream = this.model.postStream;
if (!nearestPost) {
const loadedPost = postStream.findLoadedPost(this.currentPostId);
if (loadedPost) {
nearestPost = loadedPost.post_number;
} else {
- postStream.findPostsByIds([this.currentPostId]).then((arr) => {
- nearestPost = arr[0].post_number;
- });
+ try {
+ const [post] = await postStream.findPostsByIds([this.currentPostId]);
+ nearestPost = post.post_number;
+ } catch (error) {
+ popupAjaxError(error);
+ return;
+ }
}
}
postStream.cancelFilter();
- postStream
- .refresh({
- nearPost: nearestPost,
- forceLoad: true,
- })
- .then(() => {
- DiscourseURL.routeTo(this.model.urlForPostNumber(nearestPost));
- this.updateQueryParams();
- });
+ await postStream.refresh({ nearPost: nearestPost, forceLoad: true });
+ DiscourseURL.routeTo(this.model.urlForPostNumber(nearestPost));
+ this.updateQueryParams();
}
@action
@@ -1539,7 +1537,7 @@ export default class TopicController extends Controller {
}
}
- _jumpToPostId(postId) {
+ async _jumpToPostId(postId) {
if (!postId) {
// eslint-disable-next-line no-console
console.warn(
@@ -1550,25 +1548,21 @@ export default class TopicController extends Controller {
this.appEvents.trigger("topic:jump-to-post", postId);
- const topic = this.model;
- const postStream = topic.get("postStream");
- const post = postStream.findLoadedPost(postId);
+ const postStream = this.model.postStream;
+ let post = postStream.findLoadedPost(postId);
- if (post) {
- DiscourseURL.routeTo(topic.urlForPostNumber(post.get("post_number")), {
- keepFilter: true,
- });
- } else {
- // need to load it
- postStream.findPostsByIds([postId]).then((arr) => {
- DiscourseURL.routeTo(
- topic.urlForPostNumber(arr[0].get("post_number")),
- {
- keepFilter: true,
- }
- );
- });
+ if (!post) {
+ try {
+ [post] = await postStream.findPostsByIds([postId]);
+ } catch (error) {
+ popupAjaxError(error);
+ return;
+ }
}
+
+ DiscourseURL.routeTo(this.model.urlForPostNumber(post.post_number), {
+ keepFilter: true,
+ });
}
_modifyTopicBookmark(bookmark) {
diff --git a/frontend/discourse/app/models/post-stream.js b/frontend/discourse/app/models/post-stream.js
index be5432bc7d9..fd39c1769a2 100644
--- a/frontend/discourse/app/models/post-stream.js
+++ b/frontend/discourse/app/models/post-stream.js
@@ -1187,9 +1187,11 @@ export default class PostStream extends RestModel {
}
} catch (error) {
// If we get a 403 error, refresh the window to prevent continuous retries
- if (error.jqXHR && error.jqXHR.status === 403) {
+ if (error.jqXHR?.status === 403) {
window.location.reload();
+ return;
}
+ throw error;
}
}
diff --git a/frontend/discourse/tests/unit/models/post-stream-test.js b/frontend/discourse/tests/unit/models/post-stream-test.js
index 92b67a76b00..0ad29b65826 100644
--- a/frontend/discourse/tests/unit/models/post-stream-test.js
+++ b/frontend/discourse/tests/unit/models/post-stream-test.js
@@ -1022,4 +1022,17 @@ module("Unit | Model | post-stream", function (hooks) {
assert.strictEqual(postStream.progressIndexOfPostId(post), 5);
});
+
+ test("loadIntoIdentityMap re-throws non-403 errors", async function (assert) {
+ const postStream = buildStream.call(this, 9999);
+
+ pretender.get("/t/9999/posts.json", () => {
+ return response(500, { error: "Internal Server Error" });
+ });
+
+ await assert.rejects(
+ postStream.loadIntoIdentityMap([1]),
+ (error) => error.jqXHR && error.jqXHR.status === 500
+ );
+ });
});