Skip to content

Commit 66c30f7

Browse files
committed
crate: Show "Crate not found" error page instead of notification
1 parent 5dc56b8 commit 66c30f7

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

app/routes/crate.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,18 @@ import { inject as service } from '@ember/service';
33

44
export default class CrateRoute extends Route {
55
@service headData;
6-
@service notifications;
6+
@service router;
77
@service store;
88

9-
async model(params) {
9+
async model(params, transition) {
1010
try {
1111
return await this.store.find('crate', params.crate_id);
1212
} catch (error) {
1313
if (error.errors?.some(e => e.detail === 'Not Found')) {
14-
this.notifications.error(`Crate '${params.crate_id}' does not exist`);
14+
this.router.replaceWith('catch-all', { transition, error, title: 'Crate not found' });
1515
} else {
16-
this.notifications.error(`Loading data for the '${params.crate_id}' crate failed. Please try again later!`);
16+
this.router.replaceWith('catch-all', { transition, error, title: 'Crate failed to load', tryAgain: true });
1717
}
18-
19-
this.replaceWith('index');
2018
}
2119
}
2220

tests/acceptance/crate-test.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,22 @@ module('Acceptance | crate page', function (hooks) {
8383

8484
test('unknown crate shows an error message', async function (assert) {
8585
await visit('/crates/nanomsg');
86-
assert.equal(currentURL(), '/');
87-
assert.dom('[data-test-notification-message]').hasText("Crate 'nanomsg' does not exist");
86+
assert.equal(currentURL(), '/crates/nanomsg');
87+
assert.dom('[data-test-404-page]').exists();
88+
assert.dom('[data-test-title]').hasText('Crate not found');
89+
assert.dom('[data-test-go-back]').exists();
90+
assert.dom('[data-test-try-again]').doesNotExist();
8891
});
8992

9093
test('other crate loading error shows an error message', async function (assert) {
9194
this.server.get('/api/v1/crates/:crate_name', {}, 500);
9295

9396
await visit('/crates/nanomsg');
94-
assert.equal(currentURL(), '/');
95-
assert
96-
.dom('[data-test-notification-message]')
97-
.hasText("Loading data for the 'nanomsg' crate failed. Please try again later!");
97+
assert.equal(currentURL(), '/crates/nanomsg');
98+
assert.dom('[data-test-404-page]').exists();
99+
assert.dom('[data-test-title]').hasText('Crate failed to load');
100+
assert.dom('[data-test-go-back]').doesNotExist();
101+
assert.dom('[data-test-try-again]').exists();
98102
});
99103

100104
test('unknown versions fall back to latest version and show an error message', async function (assert) {

0 commit comments

Comments
 (0)