Я новичок в redux/redux-saga и создаю приложение, в котором я получаю информацию из API с помощью axios. Проблема в следующем: я получаю "Ошибка: запрос не выполнен с кодом состояния 429" почти каждый раз, когда я открываю приложение. Но я не знаю, что я делаю неправильно. Кто-нибудь может мне помочь?
Это мой код:
rootSaga.js
import { all } from '@redux-saga/core/effects'
import { handleGetCoins } from './handlers/coins'
import { GET_COINS } from '../ducks/coins'
import { GET_GRAPH } from '../ducks/graph'
import { handleGetGraph } from './handlers/graph'
export function* watcherSaga(){
yield all([
takeLatest(GET_COINS, handleGetCoins),
takeLatest(GET_GRAPH, handleGetGraph)
])
}
coins.js (из обработчиков)
import { requestGetCoins } from '../requests/coins'
import { setCoins } from '../../ducks/coins'
export function* handleGetCoins(action){
try {
//waiting for this function to finish before calling another one
const response = yield call(requestGetCoins)
const { data } = response;
yield put(setCoins(data))
//sending the data from an async quest to set the state
} catch(error){
console.log(error)
alert('Ops! Something is wrong!')
}
}
graph.js (из обработчиков)
import { call, put } from '@redux-saga/core/effects'
import { requestGetGraph } from '../requests/graph'
import { setGraph } from '../../ducks/graph'
export function* handleGetGraph(action){
try {
const response = yield call(requestGetGraph, action.arg.arg)
const { data } = response;
yield put(setGraph(data))
} catch(error){
console.log('from graph', error)
alert('Ops! Something is wrong!')
}
}
configureStore.js
import { combineReducers, createStore, applyMiddleware } from "redux";
import coinsReducer from './ducks/coins'
import graphReducer from './ducks/graph'
import createSagaMiddleware from "@redux-saga/core";
import { watcherSaga } from './sagas/rootSaga'
const reducer = combineReducers({
coins: coinsReducer,
graph: graphReducer
})
const sagaMiddleware = createSagaMiddleware();
const middleware = [sagaMiddleware]
const store = createStore(reducer, {}, applyMiddleware(...middleware))
sagaMiddleware.run(watcherSaga)
export default store;
файл уток
export const GET_COINS = "GET_COINS";
const SET_COINS = "SET_COINS";
export const getCoins = () => ({
type: GET_COINS
});
export const setCoins = (coins) => ({
type: SET_COINS,
coins
})
const initialState = {
coins: undefined
}
export default (state = initialState, action) => {
switch (action.type){
case SET_COINS:
const { coins } = action;
return {...state, coins};
default:
return state;
}
}
coins.js
import React, { useEffect } from 'react';
import { StyleSheet, FlatList, ScrollView, Text, View, Button } from 'react-native';
import { useSelector, useDispatch } from 'react-redux';
import { getCoins } from '../redux/ducks/coins';
export default function Coins() {
const dispatch = useDispatch();
const coins = useSelector((state) => state.coins.coins)
useEffect(() => {
dispatch(getCoins())
}, [])
return (
<View>
<Text>Testing Testing!</Text>
<Text>Coins {coins && <Text>Hello {coins.data[0].name}</Text>}</Text>
</View>
);
}
Пожалуйста, помогите мне и спасибо!
оказывается, проблема была с API, если кто-то использует docs.coincap.io и получает ту же проблему...