Skip to content

Adjust error page titles #4477

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions app/routes/crate.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ export default class CrateRoute extends Route {
@service store;

async model(params, transition) {
let crateName = params.crate_id;

try {
return await this.store.find('crate', params.crate_id);
return await this.store.find('crate', crateName);
} catch (error) {
if (error.errors?.some(e => e.detail === 'Not Found')) {
this.router.replaceWith('catch-all', { transition, error, title: 'Crate not found' });
let title = `${crateName}: Crate not found`;
this.router.replaceWith('catch-all', { transition, error, title });
} else {
this.router.replaceWith('catch-all', { transition, error, title: 'Crate failed to load', tryAgain: true });
let title = `${crateName}: Failed to load crate data`;
this.router.replaceWith('catch-all', { transition, error, title, tryAgain: true });
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions app/routes/crate/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ export default class VersionRoute extends Route {
try {
versions = await crate.get('versions');
} catch (error) {
return this.router.replaceWith('catch-all', { transition, error, title: 'Crate failed to load', tryAgain: true });
let title = `${crate.name}: Failed to load version data`;
return this.router.replaceWith('catch-all', { transition, error, title, tryAgain: true });
}

let version;
let requestedVersion = params.version_num;
if (requestedVersion) {
version = versions.find(version => version.num === requestedVersion);
if (!version) {
return this.router.replaceWith('catch-all', { transition, title: 'Version not found' });
let title = `${crate.name}: Version ${requestedVersion} not found`;
return this.router.replaceWith('catch-all', { transition, title });
}
} else {
let { defaultVersion } = crate;
Expand Down
8 changes: 4 additions & 4 deletions tests/acceptance/crate-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ module('Acceptance | crate page', function (hooks) {
await visit('/crates/nanomsg');
assert.equal(currentURL(), '/crates/nanomsg');
assert.dom('[data-test-404-page]').exists();
assert.dom('[data-test-title]').hasText('Crate not found');
assert.dom('[data-test-title]').hasText('nanomsg: Crate not found');
assert.dom('[data-test-go-back]').exists();
assert.dom('[data-test-try-again]').doesNotExist();
});
Expand All @@ -96,7 +96,7 @@ module('Acceptance | crate page', function (hooks) {
await visit('/crates/nanomsg');
assert.equal(currentURL(), '/crates/nanomsg');
assert.dom('[data-test-404-page]').exists();
assert.dom('[data-test-title]').hasText('Crate failed to load');
assert.dom('[data-test-title]').hasText('nanomsg: Failed to load crate data');
assert.dom('[data-test-go-back]').doesNotExist();
assert.dom('[data-test-try-again]').exists();
});
Expand All @@ -110,7 +110,7 @@ module('Acceptance | crate page', function (hooks) {

assert.equal(currentURL(), '/crates/nanomsg/0.7.0');
assert.dom('[data-test-404-page]').exists();
assert.dom('[data-test-title]').hasText('Version not found');
assert.dom('[data-test-title]').hasText('nanomsg: Version 0.7.0 not found');
assert.dom('[data-test-go-back]').exists();
assert.dom('[data-test-try-again]').doesNotExist();
});
Expand All @@ -126,7 +126,7 @@ module('Acceptance | crate page', function (hooks) {
await click('[data-test-just-updated] [data-test-crate-link="0"]');
assert.equal(currentURL(), '/crates/nanomsg');
assert.dom('[data-test-404-page]').exists();
assert.dom('[data-test-title]').hasText('Crate failed to load');
assert.dom('[data-test-title]').hasText('nanomsg: Failed to load version data');
assert.dom('[data-test-go-back]').doesNotExist();
assert.dom('[data-test-try-again]').exists();
});
Expand Down
4 changes: 2 additions & 2 deletions tests/routes/crate/range-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ module('Route | crate.range', function (hooks) {
await visit('/crates/foo/range/^3');
assert.equal(currentURL(), '/crates/foo/range/%5E3');
assert.dom('[data-test-404-page]').exists();
assert.dom('[data-test-title]').hasText('Crate not found');
assert.dom('[data-test-title]').hasText('foo: Crate not found');
assert.dom('[data-test-go-back]').exists();
assert.dom('[data-test-try-again]').doesNotExist();
});
Expand All @@ -93,7 +93,7 @@ module('Route | crate.range', function (hooks) {
await visit('/crates/foo/range/^3');
assert.equal(currentURL(), '/crates/foo/range/%5E3');
assert.dom('[data-test-404-page]').exists();
assert.dom('[data-test-title]').hasText('Crate failed to load');
assert.dom('[data-test-title]').hasText('foo: Failed to load crate data');
assert.dom('[data-test-go-back]').doesNotExist();
assert.dom('[data-test-try-again]').exists();
});
Expand Down
2 changes: 1 addition & 1 deletion tests/routes/crate/version/model-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module('Route | crate.version | model() hook', function (hooks) {
await visit('/crates/foo/2.0.0');
assert.equal(currentURL(), `/crates/foo/2.0.0`);
assert.dom('[data-test-404-page]').exists();
assert.dom('[data-test-title]').hasText('Version not found');
assert.dom('[data-test-title]').hasText('foo: Version 2.0.0 not found');
assert.dom('[data-test-go-back]').exists();
assert.dom('[data-test-try-again]').doesNotExist();
});
Expand Down