Add error message if loading fails

This commit is contained in:
2020-06-01 15:51:55 +02:00
parent 053eb38cd2
commit be3a400512
3 changed files with 24 additions and 7 deletions

View File

@@ -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;
}
}