Skip to content

Commit 40c387d

Browse files
committed
Auto merge of #2471 - Turbo87:rethrow, r=locks
category|keyword: Rethrow unhandled errors When a non-404 error was returned from the backend the routes would continue with business-as-usual instead of showing the generic error page. Rethrowing the error fixes that behavior. r? @locks
2 parents 3887c09 + eef80eb commit 40c387d

File tree

5 files changed

+59
-3
lines changed

5 files changed

+59
-3
lines changed

app/routes/category.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { NotFoundError } from '@ember-data/adapter/error';
12
import Route from '@ember/routing/route';
23
import { inject as service } from '@ember/service';
34

@@ -8,10 +9,12 @@ export default Route.extend({
89
try {
910
return await this.store.find('category', params.category_id);
1011
} catch (e) {
11-
if (e.errors.some(e => e.detail === 'Not Found')) {
12+
if (e instanceof NotFoundError) {
1213
this.flashMessages.queue(`Category '${params.category_id}' does not exist`);
1314
return this.replaceWith('index');
1415
}
16+
17+
throw e;
1518
}
1619
},
1720
});

app/routes/keyword.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { NotFoundError } from '@ember-data/adapter/error';
12
import Route from '@ember/routing/route';
23
import { inject as service } from '@ember/service';
34

@@ -8,10 +9,12 @@ export default Route.extend({
89
try {
910
return await this.store.find('keyword', keyword_id);
1011
} catch (e) {
11-
if (e.errors.some(e => e.detail === 'Not Found')) {
12+
if (e instanceof NotFoundError) {
1213
this.flashMessages.queue(`Keyword '${keyword_id}' does not exist`);
1314
return this.replaceWith('index');
1415
}
16+
17+
throw e;
1518
}
1619
},
1720
});

app/templates/error.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<h1>Something Went Wrong!</h1>
2-
<h5>{{this.model.message}}</h5>
2+
<h5 data-test-error-message>{{this.model.message}}</h5>
33
<pre>
44
{{this.model.stack}}
55
</pre>

tests/routes/category-test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { currentURL } from '@ember/test-helpers';
2+
import { setupApplicationTest } from 'ember-qunit';
3+
import { module, test } from 'qunit';
4+
5+
import setupMirage from '../helpers/setup-mirage';
6+
import { visit } from '../helpers/visit-ignoring-abort';
7+
8+
module('Route | category', function (hooks) {
9+
setupApplicationTest(hooks);
10+
setupMirage(hooks);
11+
12+
test("shows an error message if the category can't be found", async function (assert) {
13+
await visit('/categories/unknown');
14+
assert.equal(currentURL(), '/');
15+
assert.dom('[data-test-flash-message]').hasText("Category 'unknown' does not exist");
16+
});
17+
18+
test('server error causes the error page to be shown', async function (assert) {
19+
this.server.get('/api/v1/categories/:categoryId', {}, 500);
20+
21+
await visit('/categories/error');
22+
assert.equal(currentURL(), '/categories/error');
23+
assert.dom('[data-test-error-message]').includesText('GET /api/v1/categories/error returned a 500');
24+
});
25+
});

tests/routes/keyword-test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { currentURL } from '@ember/test-helpers';
2+
import { setupApplicationTest } from 'ember-qunit';
3+
import { module, test } from 'qunit';
4+
5+
import setupMirage from '../helpers/setup-mirage';
6+
import { visit } from '../helpers/visit-ignoring-abort';
7+
8+
module('Route | keyword', function (hooks) {
9+
setupApplicationTest(hooks);
10+
setupMirage(hooks);
11+
12+
test("shows an error message if the keyword can't be found", async function (assert) {
13+
await visit('/keywords/unknown');
14+
assert.equal(currentURL(), '/');
15+
assert.dom('[data-test-flash-message]').hasText("Keyword 'unknown' does not exist");
16+
});
17+
18+
test('server error causes the error page to be shown', async function (assert) {
19+
this.server.get('/api/v1/keywords/:keywordId', {}, 500);
20+
21+
await visit('/keywords/error');
22+
assert.equal(currentURL(), '/keywords/error');
23+
assert.dom('[data-test-error-message]').includesText('GET /api/v1/keywords/error returned a 500');
24+
});
25+
});

0 commit comments

Comments
 (0)