Skip to content

Commit

Permalink
feat: handle wrong response from realt community
Browse files Browse the repository at this point in the history
  • Loading branch information
frederic-maury committed Nov 17, 2024
1 parent eb28ebb commit e038d3d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "realt-properties-map-frontend",
"version": "1.5.5",
"version": "1.5.6",
"license": "Apache-2.0",
"scripts": {
"start": "PORT=3010 react-scripts start",
Expand Down
16 changes: 6 additions & 10 deletions frontend/src/services/realtokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,13 @@ export async function getRealTokens(): Promise<{
realtokens: Array<RealToken>,
}> {
const http = httpRequester();
try {
const response = await http.get<Array<RealToken>>(`${Env.REACT_APP_REALT_PROPERTIES_BACKEND_URL}properties`);
return {
realtokens: response.data,
};
} catch (error) {
return {
error: true,
realtokens: [],
};
const response = await http.get<Array<RealToken>>(`${Env.REACT_APP_REALT_PROPERTIES_BACKEND_URL}properties`);
if (!Array.isArray(response.data)) {
throw new Error('Invalid response');
}
return {
realtokens: response.data,
};
}

export function mapPropertiesList(
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/store/realtokens/realtokensReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ export function fetchRealtokens(t: TFunction<'common', 'notifications'>) {
})

try {
const data = await getRealTokens();
dispatch(setRealtokens(data.realtokens));
const { realtokens } = await getRealTokens();
dispatch(setRealtokens(realtokens));
showSuccess({
title: t('realtokens.successLoadingTitle'),
message: t('realtokens.successLoadingMessage'),
});
} catch (error) {
dispatch(setRealtokens([]));
showError({
title: t('realtokens.errorLoadingTitle'),
message: t('tryAgainLater'),
Expand Down

0 comments on commit e038d3d

Please sign in to comment.