U
U
uRoot2022-01-21 14:08:44
JavaScript
uRoot, 2022-01-21 14:08:44

How to track all outgoing JS requests?

How can you track all outgoing requests for JS? I need to catch a 503 error on the response. Walking through all requests and prescribing if (err === 503) is not a variant. It needs to be done somewhere in one place. It should be some kind of addEventListener type watcher on the entire document, which will see that the request has been completed, even if the page is already loaded, and inside I could check the status of the response.

PS I need to check for statuses in the code, in JS. On what specific endpoints the request is made, I also do not know.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2022-01-21
@Aleksandr-JS-Developer

I need to catch a 503 error on the response. Walking through all requests and prescribing if (err === 503) is not a variant.

It is because of such situations that abstractions are made over the API so that the request function is one.
See f12 -> network. Sort the list of response codes, 5xx will drop out at the end

I
Immortal_pony, 2022-01-22
@Immortal_pony

To do this, you need to intercept all fetch and xhr requests,
Here is a mini-library that will help with this:
https://gist.github.com/benjamingr/0433b52559ad61f...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question