import RequestError from "../models/RequestError"; import UserStatsResponse from "../models/UserStatsResponse"; export default class UserStatsService { private apiURL = 'https://api.tsotr.humenius.me/stats' private requestInit: RequestInit = { method: 'GET', headers: { 'Content-Type': 'application/json' } }; async getStats(seasonId: string): Promise { return fetch(this.apiURL, this.requestInit) .then(res => UserStatsService.checkResponse(res)) .then(data => data.json()); } private static checkResponse(response: any): any { if (!response.ok) { console.log(response); let error = new RequestError(response.statusText); error.response = response; throw error; } return response; } }