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

Cannot read property 'apply' of undefined #12

Open
MartinDawson opened this issue Jul 23, 2017 · 4 comments
Open

Cannot read property 'apply' of undefined #12

MartinDawson opened this issue Jul 23, 2017 · 4 comments

Comments

@MartinDawson
Copy link

MartinDawson commented Jul 23, 2017

This happens when I specify the requestError function. Tested it in a new create-react-app with https://github.com/github/fetch.

import fetchIntercept from 'fetch-intercept';

const unregister = fetchIntercept.register({
  requestError: (error) => {
    return Promise.reject(error);
  },
  responseError: (error) => {
    // catches bad error here
    return Promise.reject(error);
  },
});

fetch('http://google.com');

// Unregister your interceptor
unregister();

Looking at the source, _ref.request is undefined.

	  reversedInterceptors.forEach(function (_ref) {
	    var request = _ref.request; // request is undefined
	    var requestError = _ref.requestError;
	
	    if (request || requestError) {
	      promise = promise.then(function (args) {
	        return request.apply(undefined, _toConsumableArray(args));
	      }, requestError);
	    }
	  });
@TheDutchCoder
Copy link

Same issue here.

@mlegenhausen
Copy link
Owner

Seems like the check for request comes to late. Should be an easy fix. Pull requests are welcome.

@RusinovAnton
Copy link

RusinovAnton commented Jul 6, 2018

Temporary workaround should be defining request function at least as empty:

{
  request: () => {},
  requestError: yourRequestErrorFunction,
}

@RusinovAnton
Copy link

Looked at the tests and figured out that requestError is pointless without request interceptor because requestError would only catch errors from interceptors?

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

No branches or pull requests

4 participants