Skip to main content

9.13 Adding Interceptors To Execute Code Globally

index.js

index.js
import axios from "axios";
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
import "./index.css";
import registerServiceWorker from "./registerServiceWorker";

axios.interceptors.request.use(
(request) => {
console.log(request);
// Edit request config
return request;
},
(error) => {
console.log(error);
return Promise.reject(error);
}
);

axios.interceptors.response.use(
(response) => {
console.log(response);
// Edit response config
return response;
},
(error) => {
console.log(error);
return Promise.reject(error);
}
);

ReactDOM.render(<App />, document.getElementById("root"));
registerServiceWorker();