I'm trying to create an API middleware which will react to every 401 response from the API. I've tried to search for possible solutions, but I'm kinda lost here.I have created a special 401 response on server-side, which returns me a proper JSON with 401 status code and I basically process it in the middleware and always call for RECEIVE_IS_AUTHENTICATED action if such status is returned.Small note, I understand this is nowhere near finished code, but I'm just wondering, If you guys think that terminating 401s like this is generally a good idea.import { RECEIVE_IS_AUTHENTICATED } from '../constants/ActionTypes'const BASE_URL = 'http://127.0.0.1:8000/'function callApi(endpoint) {    let config = {}    return fetch(BASE_URL + endpoint, config)        .then(response =>            response.json().then(json => {                if (!response.ok) {                    if (response.status === 401) {                        json.unauthorized = true;                    }                    return Promise.reject(json)                }                return json            })        )}export const CALL_API = Symbol('Call API')export default store => next => action => {    const callAPI = action[CALL_API]    if (typeof callAPI === 'undefined') {        return next(action)    }    let { endpoint, types } = callAPI    const [ requestType, successType, errorType ] = types    return callApi(endpoint).        then(            response => next({                response,                type: successType            }),            error => {                if (error.unauthorized) {                    return next({                        type: RECEIVE_IS_AUTHENTICATED,                        isAuthenticated: false,                    })                }                return next({                    error: error.message || 'Unknown API call error',                    type: errorType                })            }        )}
React/Redux 401 Middleware
javascript;react.js;redux