Skip to content

Commit 72a9a98

Browse files
committed
version: Show "Version not found" error page instead of notification
1 parent 70c71fe commit 72a9a98

File tree

3 files changed

+24
-22
lines changed

3 files changed

+24
-22
lines changed

app/routes/crate/version.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,25 @@ import { didCancel } from 'ember-concurrency';
66
import { AjaxError } from '../../utils/ajax';
77

88
export default class VersionRoute extends Route {
9-
@service notifications;
9+
@service router;
1010
@service sentry;
1111

12-
async model(params) {
12+
async model(params, transition) {
1313
let crate = this.modelFor('crate');
1414

1515
let versions;
1616
try {
1717
versions = await crate.get('versions');
18-
} catch {
19-
this.notifications.error(`Loading data for the '${crate.name}' crate failed. Please try again later!`);
20-
this.replaceWith('index');
21-
return;
18+
} catch (error) {
19+
return this.router.replaceWith('catch-all', { transition, error, title: 'Crate failed to load', tryAgain: true });
2220
}
2321

2422
let version;
2523
let requestedVersion = params.version_num;
2624
if (requestedVersion) {
2725
version = versions.find(version => version.num === requestedVersion);
2826
if (!version) {
29-
this.notifications.error(`Version '${requestedVersion}' of crate '${crate.name}' does not exist`);
30-
this.replaceWith('crate.index');
27+
return this.router.replaceWith('catch-all', { transition, title: 'Version not found' });
3128
}
3229
} else {
3330
let { defaultVersion } = crate;

tests/acceptance/crate-test.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,11 @@ module('Acceptance | crate page', function (hooks) {
108108

109109
await visit('/crates/nanomsg/0.7.0');
110110

111-
assert.equal(currentURL(), '/crates/nanomsg');
112-
assert.dom('[data-test-heading] [data-test-crate-name]').hasText('nanomsg');
113-
assert.dom('[data-test-heading] [data-test-crate-version]').hasText('0.6.1');
114-
assert.dom('[data-test-notification-message]').hasText("Version '0.7.0' of crate 'nanomsg' does not exist");
111+
assert.equal(currentURL(), '/crates/nanomsg/0.7.0');
112+
assert.dom('[data-test-404-page]').exists();
113+
assert.dom('[data-test-title]').hasText('Version not found');
114+
assert.dom('[data-test-go-back]').exists();
115+
assert.dom('[data-test-try-again]').doesNotExist();
115116
});
116117

117118
test('other versions loading error shows an error message', async function (assert) {
@@ -123,10 +124,11 @@ module('Acceptance | crate page', function (hooks) {
123124

124125
await visit('/');
125126
await click('[data-test-just-updated] [data-test-crate-link="0"]');
126-
assert.equal(currentURL(), '/');
127-
assert
128-
.dom('[data-test-notification-message]')
129-
.hasText("Loading data for the 'nanomsg' crate failed. Please try again later!");
127+
assert.equal(currentURL(), '/crates/nanomsg');
128+
assert.dom('[data-test-404-page]').exists();
129+
assert.dom('[data-test-title]').hasText('Crate failed to load');
130+
assert.dom('[data-test-go-back]').doesNotExist();
131+
assert.dom('[data-test-try-again]').exists();
130132
});
131133

132134
test('navigating to the all versions page', async function (assert) {

tests/routes/crate/version/model-test.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { currentURL, visit } from '@ember/test-helpers';
1+
import { currentURL } from '@ember/test-helpers';
22
import { module, test } from 'qunit';
33

44
import { setupApplicationTest } from 'cargo/tests/helpers';
55

6+
import { visit } from '../../../helpers/visit-ignoring-abort';
7+
68
module('Route | crate.version | model() hook', function (hooks) {
79
setupApplicationTest(hooks);
810

@@ -20,17 +22,18 @@ module('Route | crate.version | model() hook', function (hooks) {
2022
assert.dom('[data-test-notification-message]').doesNotExist();
2123
});
2224

23-
test('redirects to unspecific version URL', async function (assert) {
25+
test('shows error page for unknown versions', async function (assert) {
2426
let crate = this.server.create('crate', { name: 'foo' });
2527
this.server.create('version', { crate, num: '1.0.0' });
2628
this.server.create('version', { crate, num: '1.2.3', yanked: true });
2729
this.server.create('version', { crate, num: '2.0.0-beta.1' });
2830

2931
await visit('/crates/foo/2.0.0');
30-
assert.equal(currentURL(), `/crates/foo`);
31-
assert.dom('[data-test-crate-name]').hasText('foo');
32-
assert.dom('[data-test-crate-version]').hasText('1.0.0');
33-
assert.dom('[data-test-notification-message="error"]').hasText("Version '2.0.0' of crate 'foo' does not exist");
32+
assert.equal(currentURL(), `/crates/foo/2.0.0`);
33+
assert.dom('[data-test-404-page]').exists();
34+
assert.dom('[data-test-title]').hasText('Version not found');
35+
assert.dom('[data-test-go-back]').exists();
36+
assert.dom('[data-test-try-again]').doesNotExist();
3437
});
3538
});
3639

0 commit comments

Comments
 (0)