How to record the lastest xhr when a error happen?

How to record the lastest xhr when a error happen?