Skip to content

Commit 88e7a01

Browse files
committed
Auto merge of #3442 - Turbo87:crate-error, r=pichfl
Show generic flash message if crate data fails to load Rethrowing the error means that it ends up creating noise on Sentry even for regular network errors. Resolves #240
2 parents 980a04c + d71eec6 commit 88e7a01

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

app/routes/crate.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ export default class CrateRoute extends Route {
1010
} catch (error) {
1111
if (error.errors?.some(e => e.detail === 'Not Found')) {
1212
this.notifications.error(`Crate '${params.crate_id}' does not exist`);
13-
this.replaceWith('index');
1413
} else {
15-
throw error;
14+
this.notifications.error(`Loading data for the '${params.crate_id}' crate failed. Please try again later!`);
1615
}
16+
17+
this.replaceWith('index');
1718
}
1819
}
1920

app/routes/crate/version.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@ export default class VersionRoute extends Route {
1111

1212
async model(params) {
1313
let crate = this.modelFor('crate');
14-
let versions = await crate.get('versions');
14+
15+
let versions;
16+
try {
17+
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;
22+
}
1523

1624
let version;
1725
let requestedVersion = params.version_num;

tests/acceptance/crate-test.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { click, currentRouteName, currentURL, visit, waitFor } from '@ember/test-helpers';
1+
import { click, currentRouteName, currentURL, waitFor } from '@ember/test-helpers';
22
import { module, skip, test } from 'qunit';
33

44
import percySnapshot from '@percy/ember';
@@ -8,6 +8,7 @@ import { getPageTitle } from 'ember-page-title/test-support';
88
import { setupApplicationTest } from 'cargo/tests/helpers';
99

1010
import axeConfig from '../axe-config';
11+
import { visit } from '../helpers/visit-ignoring-abort';
1112

1213
module('Acceptance | crate page', function (hooks) {
1314
setupApplicationTest(hooks);
@@ -80,6 +81,22 @@ module('Acceptance | crate page', function (hooks) {
8081
await a11yAudit(axeConfig);
8182
});
8283

84+
test('unknown crate shows an error message', async function (assert) {
85+
await visit('/crates/nanomsg');
86+
assert.equal(currentURL(), '/');
87+
assert.dom('[data-test-notification-message]').hasText("Crate 'nanomsg' does not exist");
88+
});
89+
90+
test('other crate loading error shows an error message', async function (assert) {
91+
this.server.get('/api/v1/crates/:crate_name', {}, 500);
92+
93+
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!");
98+
});
99+
83100
test('unknown versions fall back to latest version and show an error message', async function (assert) {
84101
this.server.create('crate', { name: 'nanomsg' });
85102
this.server.create('version', { crateId: 'nanomsg', num: '0.6.0' });
@@ -93,6 +110,21 @@ module('Acceptance | crate page', function (hooks) {
93110
assert.dom('[data-test-notification-message]').hasText("Version '0.7.0' of crate 'nanomsg' does not exist");
94111
});
95112

113+
test('other versions loading error shows an error message', async function (assert) {
114+
this.server.create('crate', { name: 'nanomsg' });
115+
this.server.create('version', { crateId: 'nanomsg', num: '0.6.0' });
116+
this.server.create('version', { crateId: 'nanomsg', num: '0.6.1' });
117+
118+
this.server.get('/api/v1/crates/:crate_name/versions', {}, 500);
119+
120+
await visit('/');
121+
await click('[data-test-just-updated] [data-test-crate-link="0"]');
122+
assert.equal(currentURL(), '/');
123+
assert
124+
.dom('[data-test-notification-message]')
125+
.hasText("Loading data for the 'nanomsg' crate failed. Please try again later!");
126+
});
127+
96128
test('navigating to the all versions page', async function (assert) {
97129
this.server.loadFixtures();
98130

0 commit comments

Comments
 (0)