Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an interceptor functionality #132

Closed
kkamkou opened this issue Feb 18, 2018 · 2 comments
Closed

Add an interceptor functionality #132

kkamkou opened this issue Feb 18, 2018 · 2 comments

Comments

@kkamkou
Copy link

kkamkou commented Feb 18, 2018

It would be nice to have an option to modify the api (the instance or request) dynamically. The close examples are interceptor or middleware. The closest case is to add a global header for each request without modifying the get method or use the 3rd argument.

ie:

api.interceptors.push((request, next) => {
  request.headers.set('example', 'example');
  next();
});
@wopian wopian added this to the 5.0.0 milestone Feb 20, 2018
@wopian wopian removed this from the 5.x.x milestone Nov 19, 2019
@wopian
Copy link
Owner

wopian commented Nov 19, 2019

I think 5.0.0 changed the Axios usage (or somewhere in 2018) to fully expose it - so the following was possible:

const api = new Kitsu()
api.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);
  });

PR above will also add it as an alias for it directly on the class (api.interceptors) when its merged.

@wopian
Copy link
Owner

wopian commented Nov 22, 2019

api.interceptors will be in 7.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants