File tree Expand file tree Collapse file tree 5 files changed +59
-3
lines changed Expand file tree Collapse file tree 5 files changed +59
-3
lines changed Original file line number Diff line number Diff line change
1
+ import { NotFoundError } from '@ember-data/adapter/error' ;
1
2
import Route from '@ember/routing/route' ;
2
3
import { inject as service } from '@ember/service' ;
3
4
@@ -8,10 +9,12 @@ export default Route.extend({
8
9
try {
9
10
return await this . store . find ( 'category' , params . category_id ) ;
10
11
} catch ( e ) {
11
- if ( e . errors . some ( e => e . detail === 'Not Found' ) ) {
12
+ if ( e instanceof NotFoundError ) {
12
13
this . flashMessages . queue ( `Category '${ params . category_id } ' does not exist` ) ;
13
14
return this . replaceWith ( 'index' ) ;
14
15
}
16
+
17
+ throw e ;
15
18
}
16
19
} ,
17
20
} ) ;
Original file line number Diff line number Diff line change
1
+ import { NotFoundError } from '@ember-data/adapter/error' ;
1
2
import Route from '@ember/routing/route' ;
2
3
import { inject as service } from '@ember/service' ;
3
4
@@ -8,10 +9,12 @@ export default Route.extend({
8
9
try {
9
10
return await this . store . find ( 'keyword' , keyword_id ) ;
10
11
} catch ( e ) {
11
- if ( e . errors . some ( e => e . detail === 'Not Found' ) ) {
12
+ if ( e instanceof NotFoundError ) {
12
13
this . flashMessages . queue ( `Keyword '${ keyword_id } ' does not exist` ) ;
13
14
return this . replaceWith ( 'index' ) ;
14
15
}
16
+
17
+ throw e ;
15
18
}
16
19
} ,
17
20
} ) ;
Original file line number Diff line number Diff line change 1
1
<h1 >Something Went Wrong!</h1 >
2
- <h5 >{{ this.model.message }} </h5 >
2
+ <h5 data-test-error-message >{{ this.model.message }} </h5 >
3
3
<pre >
4
4
{{ this.model.stack }}
5
5
</pre >
Original file line number Diff line number Diff line change
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
+ } ) ;
Original file line number Diff line number Diff line change
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
+ } ) ;
You can’t perform that action at this time.
0 commit comments