I need to catch error 401 Code of response so that I can retry after getting a new token from token endpoint. I am using fetch method get data from API.
const
(function () { var originalFetch = fetch; fetch = function() { return originalFetch.apply(this, arguments).then(function(data) { someFunctionToDoSomething(); return data; }); };})();
source Can one use the Fetch API as a Request Interceptor?