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

Support interceptors #14

mzabriskie opened this issue Sep 22, 2014 · 4 comments


Copy link

commented Sep 22, 2014

@mzabriskie mzabriskie changed the title Support request interceptors Support interceptors Oct 14, 2014


This comment has been minimized.

Copy link

commented Oct 25, 2014

Can I help with this? I'm using js-data and I need this working for my authentication to work :-)


This comment has been minimized.

Copy link

commented Dec 2, 2014



This comment has been minimized.

Copy link
Member Author

commented Dec 2, 2014

Here's a couple approaches for the API that might work:

// 1) This style follows Angular's $http service
  request: function (config) {},
  requestError: function (rejection) {},
  response: function (response) {},
  responseError: function (rejection) {}

// 2) This style follows express middleware
axios.interceptors.request.use(function (config) {}, function (rejection) {});
axios.interceptors.response.use(function (config) {}, function (rejection) {});

The first option has the benefit of familiarity for those coming from Angular. That said it is not enough to mimic an API based on familiarity, especially if it's not a good API. As @jmdobry mentioned offline, "pushing stuff into some random array [is] kinda dumb". I agree that arbitrarily pushing some config object onto an array is less than ideal.

The second option allows for simplicity by just passing in a function, and axios knowing if the function is to be used for request, or response. It is a little uglier to only specify a requestError handler for example, since you have to provide a null value for the request handler:

axios.interceptors.request.use(null, function (rejection) {});

A third option could be to do a hybrid of the two. Expose an API that supports the second option, but under the hood it just creates what option one is doing. This would allow for both options to be supported.


This comment has been minimized.

Copy link
Member Author

commented Dec 8, 2014

Closed with #27

@mzabriskie mzabriskie closed this Dec 8, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
3 participants
You can’t perform that action at this time.