suhaotian / xior

A lite request lib based on fetch with plugin support and similar API to axios.
https://suhaotian.github.io/xior/
MIT License
193 stars 4 forks source link

Response interceptor is not working if you define a custom plugin #29

Closed guoyunhe closed 2 months ago

guoyunhe commented 2 months ago

In the following example, I added a request interceptor, a response interceptor and a plugin. However, the response interceptor is not working as long as here is the plugin. Remove the plugin and the response interceptor is working again. Request interceptor is not affected.

import xior from "xior";

xior.interceptors.request.use((request) => {
  document.getElementById("request").textContent =
    "Request Interceptor Is Working!";
  return request;
});

xior.interceptors.response.use((response) => {
  document.getElementById("response").textContent =
    "Response Interceptor Is Working!";
  return response;
});

xior.plugins.use((adaptor) => async (request) => ({
  status: 200,
  statusText: "OK",
  data: {
    foo: "bar",
  },
}));

xior.get("/");

https://codesandbox.io/p/sandbox/xior-plugin-interceptor-24xfhk

suhaotian commented 2 months ago

Work now:

https://codesandbox.io/p/sandbox/xior-plugin-interceptor-forked-l2ptr8?file=%2Fpackage.json%3A18%2C1-19%2C1