Add error message if loading fails
This commit is contained in:
@@ -13,6 +13,14 @@ export default class UserStatsService {
|
||||
async getStats(): Promise<TableEntry[]> {
|
||||
return fetch(this.apiURL, this.requestInit)
|
||||
.then(res => { console.log(res); return res; })
|
||||
.then(res => res.json())
|
||||
.then(res => this.checkResponse(res))
|
||||
.then(data => data.json())
|
||||
}
|
||||
|
||||
private checkResponse(response: any): any {
|
||||
if (!response.ok) {
|
||||
throw Error(response.statusText);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user