Unauthorized Responses
Your server
Action Creators
export function readBook(id) {
return function(dispatch) {
dispatch({
type: actionTypes.READ_RESOURCES_PENDING,
resourceType: 'books',
resources: [id]
});
// `request` would be whatever function you are using to make HTTP
// requests. It could be `window.fetch()`, axios, superagent, xhr,
// or anything else that you prefer.
request('/some-url', (err, res) => {
// Different libraries attach the status code to different properties.
// It is usually either `res.status` or `res.statusCode`. You do not
// need to check both properties if you know which one your library uses.
if (err || res.statusCode >= 400 || res.status >= 400) {
dispatch({
type: actionTypes.READ_RESOURCES_FAILED,
resourceType: 'books',
resources: [id],
requestProperties: {
statusCode: res.statusCode
}
});
return;
}
// Check to see if the request was cancelled, or if it succeeded, then
// dispatch the appropriate action here.
});
}
}Reducer
Last updated