Skip to content

Commit 55924b7

Browse files
committed
crate.range: Show 404 page instead of error notification
1 parent 8869cab commit 55924b7

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

app/routes/crate/range.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default class VersionRoute extends Route {
1111
@service notifications;
1212
@service router;
1313

14-
async model({ range }) {
14+
async model({ range }, transition) {
1515
let crate = this.modelFor('crate');
1616

1717
let versions = await crate.get('versions');
@@ -21,11 +21,11 @@ export default class VersionRoute extends Route {
2121
let npmRange = cargoRangeToNpm(range);
2222
// find a version that matches the specified range
2323
let versionNum = maxSatisfying(unyankedVersionNums, npmRange) ?? maxSatisfying(allVersionNums, npmRange);
24-
if (!versionNum) {
25-
this.notifications.error(`No matching version of crate '${crate.name}' found for: ${range}`);
26-
this.router.replaceWith('crate.index');
24+
if (versionNum) {
25+
this.router.replaceWith('crate.version', versionNum);
26+
} else {
27+
let title = `${crate.name}: No matching version found for ${range}`;
28+
this.router.replaceWith('catch-all', { transition, title });
2729
}
28-
29-
this.router.replaceWith('crate.version', versionNum);
3030
}
3131
}

tests/routes/crate/range-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.range', function (hooks) {
79
setupApplicationTest(hooks);
810

@@ -76,17 +78,18 @@ module('Route | crate.range', function (hooks) {
7678
assert.dom('[data-test-notification-message]').doesNotExist();
7779
});
7880

79-
test('redirects to main crate page if no match found', async function (assert) {
81+
test('shows an error page if no match found', async function (assert) {
8082
let crate = this.server.create('crate', { name: 'foo' });
8183
this.server.create('version', { crate, num: '1.0.0' });
8284
this.server.create('version', { crate, num: '1.1.0' });
8385
this.server.create('version', { crate, num: '1.1.1' });
8486
this.server.create('version', { crate, num: '2.0.0' });
8587

8688
await visit('/crates/foo/range/^3');
87-
assert.equal(currentURL(), `/crates/foo`);
88-
assert.dom('[data-test-crate-name]').hasText('foo');
89-
assert.dom('[data-test-crate-version]').hasText('2.0.0');
90-
assert.dom('[data-test-notification-message="error"]').hasText("No matching version of crate 'foo' found for: ^3");
89+
assert.equal(currentURL(), '/crates/foo/range/%5E3');
90+
assert.dom('[data-test-404-page]').exists();
91+
assert.dom('[data-test-title]').hasText('foo: No matching version found for ^3');
92+
assert.dom('[data-test-go-back]').exists();
93+
assert.dom('[data-test-try-again]').doesNotExist();
9194
});
9295
});

0 commit comments

Comments
 (0)