Skip to content

Commit

Permalink
Merge pull request #7560 from jrjohnson/5127-deleted-report
Browse files Browse the repository at this point in the history
Catch missing model 404s
  • Loading branch information
dartajax authored Jan 31, 2024
2 parents 32a5d01 + 1d2bfe0 commit b045952
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 10 deletions.
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",
);
});
});

0 comments on commit b045952

Please sign in to comment.