In the saga catch block, dispatch an action:
// saga:
catch(error) {
if(error.response.payload.error==='Unauthorized'){
yield put({
type: 'UNAUTHORIZED_REQUEST',
message: messages.unauthorizedMessage
})
}
}
Then in a reducer, update state based on the action:
const requestError = (state = null, { type, messageĀ }) => {
case 'UNAUTHORIZED_REQUEST':
return message;
default:
return state;
}
Then, have a component render the error message to reflect the updated state:
let MyComponent = ({ requestError }) => {
return (
<div>
{requestError &&
<MyErrorMessage message={requestError} />
}
{/* ... */}
</div>
)
}
MyComponent = connect(
state => ({
requestError: state.requestError
})
)(MyComponent)