+
{
seasonId > 1
- && props.onSeasonIdChange('' + (seasonId - 1))}>
-
-
+ && (props.enabled
+ ? props.onSeasonIdChange('' + (seasonId - 1))}>
+
+
+ : e.preventDefault()}>
+
+ )
}
{
seasonId < maxSeasonId
- && props.onSeasonIdChange('' + (seasonId + 1))}>
-
-
+ && (props.enabled
+ ? props.onSeasonIdChange('' + (seasonId + 1))}>
+
+
+ : e.preventDefault()}>
+
+ )
}
)
diff --git a/frontend/src/components/UserList/UserList.tsx b/frontend/src/components/UserList/UserList.tsx
index aafc117..1513529 100644
--- a/frontend/src/components/UserList/UserList.tsx
+++ b/frontend/src/components/UserList/UserList.tsx
@@ -23,7 +23,7 @@ const createTableEntries = (entries: TableEntry[]) =>
const UserList: React.FC
= (props: IUserListProperties) => (
-
+
@@ -44,6 +44,7 @@ export interface IUserListProperties {
userStats: UserStatsResponse
mocked?: boolean
onSeasonIdChange: any
+ enabled: boolean
}
export default UserList;
\ No newline at end of file
diff --git a/frontend/src/models/RequestError.ts b/frontend/src/models/RequestError.ts
index 376f0fc..7f48b63 100644
--- a/frontend/src/models/RequestError.ts
+++ b/frontend/src/models/RequestError.ts
@@ -1,3 +1,12 @@
export default class RequestError extends Error {
- response?: any;
+ //response?: any = "Unknown error. Please try again later.";
+ statusCode: number
+ message: string
+
+
+ constructor(statusCode: number, message: string) {
+ super(message);
+ this.statusCode = statusCode;
+ this.message = message;
+ }
}
diff --git a/frontend/src/pages/MainPage/MainPage.tsx b/frontend/src/pages/MainPage/MainPage.tsx
index cc74782..e16560a 100644
--- a/frontend/src/pages/MainPage/MainPage.tsx
+++ b/frontend/src/pages/MainPage/MainPage.tsx
@@ -25,7 +25,11 @@ const MainPage: FC = (props: IMainPageProps) => {
setSeasonStats(res)
setLoadingState(false)
})
- .catch(err => setError(err))
+ .catch(err => {
+ console.error(err.message)
+ setLoadingState(false)
+ setError(new RequestError(0, "Could not retrieve stats. Try again later."))
+ })
}, [seasonId, setLoadingState])
const spinnerCss = `
@@ -38,11 +42,12 @@ const MainPage: FC = (props: IMainPageProps) => {
{
- error &&
+ error &&
}
+
-
-
+
+
@@ -54,11 +59,4 @@ export interface IMainPageProps extends RouteComponentProps<{ id: string }> {
}
-interface IMainPageState {
- id: string;
- error?: string;
- loading: boolean;
- users: UserStatsResponse;
-}
-
export default withRouter(MainPage)
\ No newline at end of file
diff --git a/frontend/src/services/UserStatsService.ts b/frontend/src/services/UserStatsService.ts
index 174ef6b..2d5d2a5 100644
--- a/frontend/src/services/UserStatsService.ts
+++ b/frontend/src/services/UserStatsService.ts
@@ -5,12 +5,13 @@ export default class UserStatsService {
private static apiURL = 'https://api.tsotr.humenius.me/stats'
// private static apiURL = 'http://localhost:3500/stats'
+ //private static apiURL = 'https://mock.codes/501'
private static requestInit: RequestInit = {
method: 'GET',
headers: {
- 'Content-Type': 'application/json'
- }
+ 'Content-Type': 'application/json',
+ },
};
public static async getStats(seasonId: string): Promise
{
@@ -27,9 +28,7 @@ export default class UserStatsService {
private static checkResponse(response: any): any {
if (!response.ok) {
console.log(response);
- let error = new RequestError(response.statusText);
- error.response = response;
- throw error;
+ throw new RequestError(response.status, response.body);
}
return response;
}
diff --git a/frontend/yarn.lock b/frontend/yarn.lock
index 01194ac..4699d81 100644
--- a/frontend/yarn.lock
+++ b/frontend/yarn.lock
@@ -1667,6 +1667,11 @@
resolved "https://registry.yarnpkg.com/@types/history/-/history-4.7.8.tgz#49348387983075705fe8f4e02fb67f7daaec4934"
integrity sha512-S78QIYirQcUoo6UJZx9CSP0O2ix9IaeAXwQi26Rhr/+mg7qqPy8TzaxHSUut7eGjL8WmLccT7/MXf304WjqHcA==
+"@types/isomorphic-fetch@^0.0.35":
+ version "0.0.35"
+ resolved "https://registry.yarnpkg.com/@types/isomorphic-fetch/-/isomorphic-fetch-0.0.35.tgz#c1c0d402daac324582b6186b91f8905340ea3361"
+ integrity sha512-DaZNUvLDCAnCTjgwxgiL1eQdxIKEpNLOlTNtAgnZc50bG2copGhRrFN9/PxPBuJe+tZVLCbQ7ls0xveXVRPkvw==
+
"@types/istanbul-lib-coverage@*", "@types/istanbul-lib-coverage@^2.0.0":
version "2.0.3"
resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.3.tgz#4ba8ddb720221f432e443bd5f9117fd22cfd4762"
@@ -4801,6 +4806,11 @@ fb-watchman@^2.0.0:
dependencies:
bser "2.1.1"
+fetch-retry-ts@^1.1.23:
+ version "1.1.23"
+ resolved "https://registry.yarnpkg.com/fetch-retry-ts/-/fetch-retry-ts-1.1.23.tgz#7659974215c7a66b9bb81c006e5acee34d932ca8"
+ integrity sha512-UwqrMGfDPRa60etXl1HkDgIhY9k2AoB/Qa41/U2thzHtA/NVHGSmn037dw4iOg62ccyX2imtkU8SFfSwxLLEYA==
+
figgy-pudding@^3.5.1:
version "3.5.2"
resolved "https://registry.yarnpkg.com/figgy-pudding/-/figgy-pudding-3.5.2.tgz#b4eee8148abb01dcf1d1ac34367d59e12fa61d6e"
@@ -6169,6 +6179,14 @@ isobject@^3.0.0, isobject@^3.0.1:
resolved "https://registry.yarnpkg.com/isobject/-/isobject-3.0.1.tgz#4e431e92b11a9731636aa1f9c8d1ccbcfdab78df"
integrity sha1-TkMekrEalzFjaqH5yNHMvP2reN8=
+isomorphic-fetch@^3.0.0:
+ version "3.0.0"
+ resolved "https://registry.yarnpkg.com/isomorphic-fetch/-/isomorphic-fetch-3.0.0.tgz#0267b005049046d2421207215d45d6a262b8b8b4"
+ integrity sha512-qvUtwJ3j6qwsF3jLxkZ72qCgjMysPzDfeV240JHiGZsANBYd+EEuu35v7dfrJ9Up0Ak07D7GGSkGhCHTqg/5wA==
+ dependencies:
+ node-fetch "^2.6.1"
+ whatwg-fetch "^3.4.1"
+
isstream@~0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a"
@@ -7504,6 +7522,11 @@ no-case@^3.0.4:
lower-case "^2.0.2"
tslib "^2.0.3"
+node-fetch@^2.6.1:
+ version "2.6.1"
+ resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052"
+ integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==
+
node-forge@^0.10.0:
version "0.10.0"
resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.10.0.tgz#32dea2afb3e9926f02ee5ce8794902691a676bf3"
@@ -11312,7 +11335,7 @@ whatwg-encoding@^1.0.1, whatwg-encoding@^1.0.3, whatwg-encoding@^1.0.5:
dependencies:
iconv-lite "0.4.24"
-whatwg-fetch@^3.0.0:
+whatwg-fetch@^3.0.0, whatwg-fetch@^3.4.1:
version "3.5.0"
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-3.5.0.tgz#605a2cd0a7146e5db141e29d1c62ab84c0c4c868"
integrity sha512-jXkLtsR42xhXg7akoDKvKWE40eJeI+2KZqcp2h3NsOrRnDvtWX36KcKl30dy+hxECivdk2BVUHVNrPtoMBUx6A==