diff options
| author | Kamran Ahmed <kamranahmed.se@gmail.com> | 2018-08-28 15:47:02 +0500 |
|---|---|---|
| committer | Kamran Ahmed <kamranahmed.se@gmail.com> | 2018-08-28 15:47:02 +0500 |
| commit | f441166a3bf27c145a48ae2350cd8cd0931504e9 (patch) | |
| tree | cad4e80d88d6910cda192ec3f1f0d4d80f71f331 /src/redux | |
| parent | Alert for token (diff) | |
| download | githunt-f441166a3bf27c145a48ae2350cd8cd0931504e9.tar.gz | |
Refactor and add error handling
Diffstat (limited to 'src/redux')
| -rw-r--r-- | src/redux/github/actions.js | 25 | ||||
| -rw-r--r-- | src/redux/github/reducer.js | 8 | ||||
| -rw-r--r-- | src/redux/github/types.js | 1 |
3 files changed, 10 insertions, 24 deletions
diff --git a/src/redux/github/actions.js b/src/redux/github/actions.js index 5474144..73dba10 100644 --- a/src/redux/github/actions.js +++ b/src/redux/github/actions.js @@ -5,7 +5,6 @@ import { FETCH_TRENDING_FAILED, FETCH_TRENDING_SUCCESS, PROCESS_FETCH_TRENDING, - UPDATE_FILTERS } from './types'; const API_URL = 'https://api.github.com/search/repositories'; @@ -49,24 +48,18 @@ export const fetchTrending = function (filters) { } }); }).catch(error => { + let message = error.response && + error.response.data && + error.response.data.message; + + if (!message) { + message = error.message; + } + dispatch({ type: FETCH_TRENDING_FAILED, - payload: error + payload: message }); }); }; }; - -/** - * Updates the filters used in queries - * @param filters - * @return {Function} - */ -export const updateFilters = function (filters) { - return dispatch => { - dispatch({ - type: UPDATE_FILTERS, - payload: filters - }); - }; -}; diff --git a/src/redux/github/reducer.js b/src/redux/github/reducer.js index 79543b8..0d443f6 100644 --- a/src/redux/github/reducer.js +++ b/src/redux/github/reducer.js @@ -1,4 +1,4 @@ -import { FETCH_TRENDING_FAILED, FETCH_TRENDING_SUCCESS, PROCESS_FETCH_TRENDING, UPDATE_FILTERS } from './types'; +import { FETCH_TRENDING_FAILED, FETCH_TRENDING_SUCCESS, PROCESS_FETCH_TRENDING } from './types'; import { UPDATE_DATE_TYPE, UPDATE_LANGUAGE } from '../preference/types'; export const initialState = { @@ -9,7 +9,6 @@ export const initialState = { // { start: '', end: '', data: [] } // ] repositories: [], - filters: {}, error: null, }; @@ -44,11 +43,6 @@ export default function reducer(state = initialState, action) { processing: false, error: action.payload }; - case UPDATE_FILTERS: - return { - ...state, - filters: action.payload - }; default: return state; } diff --git a/src/redux/github/types.js b/src/redux/github/types.js index c5be4bc..a345496 100644 --- a/src/redux/github/types.js +++ b/src/redux/github/types.js @@ -1,4 +1,3 @@ export const PROCESS_FETCH_TRENDING = 'PROCESS_FETCH_TRENDING'; export const FETCH_TRENDING_SUCCESS = 'FETCH_TRENDING_SUCCESS'; export const FETCH_TRENDING_FAILED = 'FETCH_TRENDING_FAILED'; -export const UPDATE_FILTERS = 'UPDATE_FILTERS'; |
