Usage redux-api-middlewareI encountered a problem when one and only one of my reducer functions does not start.
I would like to handle failed api requests in the same way as I handle successful api requests. However, as far as I can tell, the FSA is SEARCH_FAILUREnever processed, although it is processed (AFAICT) identically to the FSA SEARCH_SUCCESS. It seems to be created and dispatched based on what I see in devtools.
I have it
import { CALL_API } from 'redux-api-middleware'
import { handleActions } from 'redux-actions'
const searchReducer = handleActions({
SEARCH_SUCCESS: (state = defaultState, action) => {
return {
...state,
search_results: ({...action.payload}),
api: {
requestPending: false,
searchPending: false
},
}
},
SEARCH_FAILURE: function(state = defaultState, action) {
console.log("Handling SEARCH_FAILURE given state, action: ", state, action)
return {
...state,
search_results: {Total: 0},
api: {
requestPending: false,
error: action.payload
},
errors: [action.payload, ...state.errors]
}
},
})
FSA SEARCH_SUCCESS searchReducer, 400, SEARCH_FAILURE - , , , . SEARCH_FAILURE redux devtools.
, , , RSAA
export function doSearch( selected_filters, page ){
let qs = SearchPage.constructQueryString(selected_filters, page)
return {
[CALL_API]: {
endpoint: `/api/songs/search?${qs}`,
method: 'GET',
types: [
{type: SEARCH_REQUEST},
{type: SEARCH_SUCCESS},
{
type: SEARCH_FAILURE,
payload: (action, state, res) => {
if (400 === res.status)
{
console.log(`${SEARCH_FAILURE} payload: `, action, state, res)
}
return res
}
},
],
headers: { 'Content-Type': 'application/json' },
credentials: 'include'
}
}
}
payload , . , ? redux-api-middleware, , , . , ...