Skip to content

Commit 7a845ad

Browse files
committed
Auto merge of #4480 - Turbo87:category-error, r=Turbo87
category: Show error page if data loading fails also similar to #4476
2 parents d3ebfc4 + 5a9a3a3 commit 7a845ad

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

app/routes/category.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@ import Route from '@ember/routing/route';
33
import { inject as service } from '@ember/service';
44

55
export default class CategoryRoute extends Route {
6-
@service notifications;
76
@service router;
87
@service store;
98

10-
async model(params) {
9+
async model(params, transition) {
10+
let categoryName = params.category_id;
11+
1112
try {
12-
return await this.store.find('category', params.category_id);
13+
return await this.store.find('category', categoryName);
1314
} catch (error) {
1415
if (error instanceof NotFoundError) {
15-
this.notifications.error(`Category '${params.category_id}' does not exist`);
16-
return this.router.replaceWith('index');
16+
let title = `${categoryName}: Category not found`;
17+
this.router.replaceWith('catch-all', { transition, title });
18+
} else {
19+
let title = `${categoryName}: Failed to load category data`;
20+
this.router.replaceWith('catch-all', { transition, error, title, tryAgain: true });
1721
}
18-
19-
throw error;
2022
}
2123
}
2224
}

tests/routes/category-test.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,22 @@ module('Route | category', function (hooks) {
99
setupApplicationTest(hooks);
1010

1111
test("shows an error message if the category can't be found", async function (assert) {
12-
await visit('/categories/unknown');
13-
assert.equal(currentURL(), '/');
14-
assert.dom('[data-test-notification-message]').hasText("Category 'unknown' does not exist");
12+
await visit('/categories/foo');
13+
assert.equal(currentURL(), '/categories/foo');
14+
assert.dom('[data-test-404-page]').exists();
15+
assert.dom('[data-test-title]').hasText('foo: Category not found');
16+
assert.dom('[data-test-go-back]').exists();
17+
assert.dom('[data-test-try-again]').doesNotExist();
1518
});
1619

1720
test('server error causes the error page to be shown', async function (assert) {
1821
this.server.get('/api/v1/categories/:categoryId', {}, 500);
1922

20-
await visit('/categories/error');
21-
assert.equal(currentURL(), '/categories/error');
22-
assert.dom('[data-test-error-message]').includesText('GET /api/v1/categories/error returned a 500');
23+
await visit('/categories/foo');
24+
assert.equal(currentURL(), '/categories/foo');
25+
assert.dom('[data-test-404-page]').exists();
26+
assert.dom('[data-test-title]').hasText('foo: Failed to load category data');
27+
assert.dom('[data-test-go-back]').doesNotExist();
28+
assert.dom('[data-test-try-again]').exists();
2329
});
2430
});

0 commit comments

Comments
 (0)