Skip to content
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

Catch missing model 404s #7560

Merged
merged 2 commits into from
Jan 31, 2024
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
8 changes: 8 additions & 0 deletions app/controllers/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,12 @@ export default class ErrorController extends Controller {
forceRefresh() {
location.reload();
}

get isA404() {
if (this.model?.errors.length > 0) {
return Number(this.model.errors[0].status) === 404;
}

return false;
}
}
1 change: 1 addition & 0 deletions app/styles/components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
@import "components/course-director-manager";
@import "components/course-search-result";
@import "components/dashboard-loading";
@import "components/error";
@import "components/filter-tools";
@import "components/flash-messages";
@import "components/global-search";
Expand Down
5 changes: 5 additions & 0 deletions app/styles/components/error.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@use "../ilios-common/mixins" as cm;

.full-screen-error {
@include cm.main-section;
}
22 changes: 13 additions & 9 deletions app/templates/error.hbs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<div class="error-main">
<h2>
{{t "general.finalErrorDisplayMessage"}}
</h2>
<p class="clear-errors">
<button type="button" {{on "click" this.forceRefresh}}>
{{t "general.refreshTheBrowser"}}
</button>
</p>
<div class="full-screen-error">
{{#if this.isA404}}
<NotFound />
{{else}}
<h2>
{{t "general.finalErrorDisplayMessage"}}
</h2>
<p class="clear-errors">
<button type="button" {{on "click" this.forceRefresh}}>
{{t "general.refreshTheBrowser"}}
</button>
</p>
{{/if}}
</div>
2 changes: 1 addition & 1 deletion ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ module.exports = function (defaults) {
'dashboard.activities',
'dashboard.calendar',
'dashboard.materials',
'error',
// 'error', don't ever split the error route, it will break error handling
'events',
'four-oh-four',
/instructor[a-z-]*/,
Expand Down
18 changes: 18 additions & 0 deletions tests/acceptance/four-oh-four-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,22 @@ module('Acceptance | FourOhFour', function (hooks) {
await visit('/nothing');
assert.strictEqual(currentRouteName(), 'four-oh-four');
});

test('visiting missing course', async function (assert) {
await visit('/courses/1337');
assert
.dom('.full-screen-error')
.hasText(
"Rats! I couldn't find that. Please check your page address, and try again. Back to Dashboard",
);
});

test('visiting missing report #5127', async function (assert) {
await visit('/reports/subjects/1989');
assert
.dom('.full-screen-error')
.hasText(
"Rats! I couldn't find that. Please check your page address, and try again. Back to Dashboard",
);
});
});
Loading