Skip to content

Commit

Permalink
return promise from getData (#90)
Browse files Browse the repository at this point in the history
* return promise from `getData`

* remove redundant `console.error`
  • Loading branch information
GalMunGral authored Oct 9, 2023
1 parent 7d15660 commit 1e50653
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ const App: FC = () => {
(stations) => {
dataActionDispatcher({ type: 'loadStations', stations });
},
console.error
() => undefined
),
getData<SpeciesSummary[]>(
'species/all/?order_by=matched_canonical_full_name',
(species) => {
dataActionDispatcher({ type: 'updateAllSpecies', species });
},
console.error
() => undefined
)
]).then(() => {
setInitialized(true);
Expand Down
4 changes: 2 additions & 2 deletions src/store/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import axios, { AxiosError } from 'axios';
import { Dayjs } from 'dayjs';

export const getData = <T>(endpoint: string, success: (data: T) => void, err: (error: Error | AxiosError) => void) => {
axios
return axios
.get(`${window.API_PATH}/${endpoint}`)
.then(({ data }) => success(data))
.catch((error) => {
console.error();
console.error(error);
err(error);
});
};
Expand Down

0 comments on commit 1e50653

Please sign in to comment.