-
Notifications
You must be signed in to change notification settings - Fork 0
/
axios.js
36 lines (34 loc) · 947 Bytes
/
axios.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
axios.interceptors.request.use((request) => {
console.log("REQUEST INCOMMING");
return request;
});
axios.interceptors.response.use((response) => {
console.log("RESPONSE INCOMMING");
return response;
});
function getData() {
// try {
// let response = await fetch("https://jsonplaceholder.typicode.com/posts/1");
// let json = await response.json();
// console.log(json);
// } catch (err) {
// console.log("FAILED", err);
// }
const controller = new AbortController();
axios
.get("https://jsonplaceholder.typicode.com/posts/1", {
signal: controller.signal,
})
.then(function (response) {
// handle success
console.log(response);
})
.catch(function (error) {
// handle error
// console.log(error);
});
setTimeout(() => {
controller.abort();
console.log("aborted");
}, 1000);
}