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

handleFetch not always needed #6

Open
amacleay opened this issue May 15, 2018 · 1 comment
Open

handleFetch not always needed #6

amacleay opened this issue May 15, 2018 · 1 comment

Comments

@amacleay
Copy link

If a consumer provides handleResponse, they generally don't need to provide handleFetch:

// ERROR: missing property handleFetch
// even though there is no need for it here
new TokenRefreshLink({
  fetchAccessToken: () => {
    const refreshedSession = refreshSession();
    const fakeReq = new Request('uri://fake');
    return Object.assign(fakeReq, refreshedSession);
  },
  handleResponse: (_, __) => response => response.text()
      .then(JSON.parse)
      .then(res => {
        saveToken(res.accessToken);
      }),
  },
  handleError: console.error,
});

Expected behavior:
The constructor should enforce that at least one of handleFetch and handleResponse are present

@newsiberian
Copy link
Owner

Hi, this code will fails because there is a check between handleResponse and handleFetch functions that expect to find a data we marked as accessTokenField, but I see your point. Originaly handleResponse was internal

I'm not sure the way you suggested will not confuse people, if we will mark handleFetch as an optional.

What do you think?

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

2 participants