How can network requests be monitored and evaluated for their request URL, parameters, request, and response data?
I want to be notified or being given a custom exception, if specific content occurs in request or response.
Assume a web application with many dynamic Ajax requests. A request or response might contain a broken value, e.g. undefined
.
Request URL:
http://localhost:8080/app/?undefined=1
Response JSON data:
{"undefined":"1"}
Guesses of what might work ...
If importing axios
, you could leverage custom interceptors:
// Add a response interceptor
axios.interceptors.response.use(function (response) {
// Any status code that lie within the range of 2xx cause this function to trigger
// Do something with response data
return response;
}, function (error) {
// Any status codes that falls outside the range of 2xx cause this function to trigger
// Do something with response error
return Promise.reject(error);
});
// Similar functionality can be achieved for request
axios.interceptors.request.use(function (config) {
// Do something before request is sent
return config;
}, function (error) {
// Do something with request error
return Promise.reject(error);
});