Skip to content

Instantly share code, notes, and snippets.

View Nainik2509's full-sized avatar
🎯
Focusing

Nainik Mehta Nainik2509

🎯
Focusing
View GitHub Profile
@Nainik2509
Nainik2509 / index.js
Created November 9, 2023 13:05
Axios Request Interceptor
import axios from 'axios';
/* The code `axios.interceptors.request.use((config) => { ... })` is creating an interceptor for Axios
requests. */
axios.interceptors.request.use((config) => {
// Log to print that request is intiated..
console.log('Request was sent');
// Data that can be keep track of which are sent in request
console.log(`[${config.method}] ${config.url}`);
@Nainik2509
Nainik2509 / index.js
Created November 9, 2023 13:21
Axios response interceptor setup
// Axios response interceptor setup
axios.interceptors.response.use(
(response) => {
// Handle successful responses
console.log('Response received:', response.data);
return response;
},
(error) => {
// Handle response errors
console.error('Error encountered:', error);