How to obtain response uniformly by node.js

there are many methods in the project to request the interface, and sometimes the token expires, so it needs to be judged and processed in each method. Is there any way for node.js to obtain the response, uniformly and then deal with it?

the foreground ajax requests the node interface. Node uses superagent to request the API interface. API returns Token expiration. Can superagent handle it uniformly at this time

Mar.01,2021

for your description, I am very confused. Is the response obtained by requesting node through ajax in the project token expired, or is node to request other interfaces and return token expiration?

as far as I understand it, you should unify error handling at the request of ajax. Then you can consider axios axios document

// 
axios.interceptors.request.use(function (config) {
    // 
    return config;
  }, function (error) {
    // 
    return Promise.reject(error);
  });

// 
axios.interceptors.response.use(function (response) {
    // 
    return response;
  }, function (error) {
    // 
    return Promise.reject(error);
  });
Menu