Skip to content

Commit 3095200

Browse files
committed
Add logging for axios requests and responses in axios.ts
1 parent 278f776 commit 3095200

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

frontend/server/axios.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,30 @@ import axios from 'axios';
22

33
const config = useRuntimeConfig()
44

5+
console.log(`[axios] Backend URL: ${config.BACKEND_URL}`)
6+
57
const axiosInstance = axios.create({
6-
baseURL: config.BACKEND_URL, // Base URL for your API
8+
baseURL: config.BACKEND_URL,
79
headers: {
810
'Content-Type': 'application/json',
911
'token': config.BACKEND_TOKEN,
1012
},
1113
});
1214

15+
axiosInstance.interceptors.request.use((req) => {
16+
console.log(`[axios] → ${req.method?.toUpperCase()} ${req.baseURL}${req.url}`)
17+
return req
18+
})
19+
20+
axiosInstance.interceptors.response.use(
21+
(res) => {
22+
console.log(`[axios] ← ${res.status} ${res.config.url}`)
23+
return res
24+
},
25+
(err) => {
26+
console.error(`[axios] ✗ ${err.config?.url}${err.message}`)
27+
return Promise.reject(err)
28+
}
29+
)
30+
1331
export default axiosInstance;

0 commit comments

Comments
 (0)