@@ -2,6 +2,7 @@ import { inject as service } from '@ember/service';
22import JSONAPIAdapter from '@ember-data/adapter/json-api' ;
33import { pluralize } from 'ember-inflector' ;
44import { isBlank } from '@ember/utils' ;
5+ import config from 'ember-api-docs/config/environment' ;
56
67export default class Application extends JSONAPIAdapter {
78 currentProject = '' ;
@@ -39,7 +40,6 @@ export default class Application extends JSONAPIAdapter {
3940
4041 async findRecord ( store , { modelName } , id ) {
4142 let url ;
42- // let host = this.host;
4343 let projectName = this . currentProject ;
4444
4545 if ( [ 'namespace' , 'class' , 'module' ] . indexOf ( modelName ) > - 1 ) {
@@ -77,10 +77,23 @@ export default class Application extends JSONAPIAdapter {
7777 throw new Error ( 'Unexpected model lookup' ) ;
7878 }
7979
80- url = `/${ url } .json` ;
80+ const base = this . fastboot . isFastBoot
81+ ? config . APP . domain
82+ : window . location . origin ;
8183
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+ }
8598 }
8699}
0 commit comments