In the following steps, we will create an axios interceptor that will work as a middleware. Follow the instructions do it correctly:
- Install the Sweet Alert package. To do this you need to open Terminal (macOS or Linux) or Command Prompt/PowerShell (Windows) and execute the following command:
> npm install --save sweetalert2
- Create a new file called interceptors.js in the src/http folder and open it.
- Then, we import the Sweet Alert package:
import Swal from 'sweetalert2';
- We need to create a constant with an array of the POST methods that will be intercepted:
const postMethods = ['post', 'patch'];
- We need to create a function named requestInterceptor and export it. This function will receive one argument, config, which is an axios configuration object. We need to check whether the request method is included in the array we created earlier and whether the data property of the data body has an id property. If any of the...