@@ -2,6 +2,7 @@ import { inject as service } from '@ember/service';
2
2
import JSONAPIAdapter from '@ember-data/adapter/json-api' ;
3
3
import { pluralize } from 'ember-inflector' ;
4
4
import { isBlank } from '@ember/utils' ;
5
+ import config from 'ember-api-docs/config/environment' ;
5
6
6
7
export default class Application extends JSONAPIAdapter {
7
8
currentProject = '' ;
@@ -39,7 +40,6 @@ export default class Application extends JSONAPIAdapter {
39
40
40
41
async findRecord ( store , { modelName } , id ) {
41
42
let url ;
42
- // let host = this.host;
43
43
let projectName = this . currentProject ;
44
44
45
45
if ( [ 'namespace' , 'class' , 'module' ] . indexOf ( modelName ) > - 1 ) {
@@ -77,10 +77,23 @@ export default class Application extends JSONAPIAdapter {
77
77
throw new Error ( 'Unexpected model lookup' ) ;
78
78
}
79
79
80
- url = `/${ url } .json` ;
80
+ const base = this . fastboot . isFastBoot
81
+ ? config . APP . domain
82
+ : window . location . origin ;
81
83
82
- let response = await fetch ( url ) ;
83
- let json = await response . json ( ) ;
84
- return json ;
84
+ url = `${ base } /${ url } .json` ;
85
+ try {
86
+ let response = await fetch ( url ) ;
87
+ if ( ! response . ok ) {
88
+ throw new Error (
89
+ `Network response was not ok: ${ response . status } ${ response . statusText } `
90
+ ) ;
91
+ }
92
+ let json = await response . json ( ) ;
93
+ return json ;
94
+ } catch ( error ) {
95
+ console . error ( `Failed to fetch or parse JSON from ${ url } :` , error ) ;
96
+ throw new Error ( `Failed to load data for ${ url } : ${ error . message } ` ) ;
97
+ }
85
98
}
86
99
}
0 commit comments