Skip to content

Commit d71eec6

Browse files
committed
Show generic flash message if versions list fails to load
Letting the error bubble up means that it ends up creating noise on Sentry even for regular network errors.
1 parent 0a54752 commit d71eec6

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,21 @@ module('Acceptance | crate page', function (hooks) {
110110
assert.dom('[data-test-notification-message]').hasText("Version '0.7.0' of crate 'nanomsg' does not exist");
111111
});
112112

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+
113128
test('navigating to the all versions page', async function (assert) {
114129
this.server.loadFixtures();
115130

0 commit comments

Comments
 (0)