Complete the code to add a request interceptor to Axios.
axios.interceptors.request.use(function(config) {
// Modify config here
return [1];
});The request interceptor must return the config object to continue the request.
Complete the code to add a response interceptor that handles errors.
axios.interceptors.response.use(function(response) {
return response;
}, function([1]) {
// Handle error
return Promise.reject(error);
});response instead of error in the error handler.Promise.reject(error) to propagate the error.The error handler function receives the error object.
Fix the error in the interceptor code to correctly add an Authorization header.
axios.interceptors.request.use(function(config) {
config.headers.Authorization = 'Bearer ' + [1];
return config;
});config or response instead of the token string.The token variable holds the authorization token string to add to headers.
Fill both blanks to create an interceptor that logs the URL and method of each request.
axios.interceptors.request.use(function(config) {
console.log('Request:', config.[1], config.[2]);
return config;
});data or headers instead of url or method.The config.url and config.method properties hold the request URL and HTTP method.
Fill all three blanks to create a response interceptor that extracts data and handles errors with a custom message.
axios.interceptors.response.use(function([1]) { return response.[2]; }, function(error) { console.error('Request failed:', error.[3]); return Promise.reject(error); });
response.data but the whole response.error.config instead of error.message.The response object is passed in, and its data property holds the server data. The error object has a message property describing the error.