Skip to content

Commit 0a54752

Browse files
committed
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.
1 parent 4c4cfe8 commit 0a54752

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
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

tests/acceptance/crate-test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,16 @@ module('Acceptance | crate page', function (hooks) {
8787
assert.dom('[data-test-notification-message]').hasText("Crate 'nanomsg' does not exist");
8888
});
8989

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+
90100
test('unknown versions fall back to latest version and show an error message', async function (assert) {
91101
this.server.create('crate', { name: 'nanomsg' });
92102
this.server.create('version', { crateId: 'nanomsg', num: '0.6.0' });

0 commit comments

Comments
 (0)