Skip to content

Commit e0a676f

Browse files
committed
category: Rethrow non-404 errors
1 parent 08e9646 commit e0a676f

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

app/routes/category.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export default Route.extend({
1212
this.flashMessages.queue(`Category '${params.category_id}' does not exist`);
1313
return this.replaceWith('index');
1414
}
15+
16+
throw e;
1517
}
1618
},
1719
});

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+
});

0 commit comments

Comments
 (0)