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

fix: handle network error in retry function and add a callback #37

Merged
merged 18 commits into from
Sep 19, 2018
Merged

fix: handle network error in retry function and add a callback #37

merged 18 commits into from
Sep 19, 2018

Conversation

ntelkedzhiev
Copy link
Contributor

@ntelkedzhiev ntelkedzhiev commented Sep 17, 2018

Closes #36

@ntelkedzhiev
Copy link
Contributor Author

ntelkedzhiev commented Sep 17, 2018

@nodkz Should forceRetry and onRetry be combined in something like onRetry(forceRetry, delay, attempt)? Also, do you want me to only handle the Network request failed error or all error that do not contain a response from the server as it is now.

@nodkz
Copy link
Collaborator

nodkz commented Sep 17, 2018

@ntelkedzhiev can you fix broken tests?
Also, run yarn lint it also throws indentation errors (tab -> 2 spaces).

Run yarn test or npm test to run all tests locally before committing.

Should forceRetry and onRetry be combined in something like onRetry(forceRetry, delay, attempt)?

While reviewing your code I came with the same idea about improvement of onRetry method.
Let's do it! 👍
But add more functionality to it - onRetry(meta: { forceRetry: Function, delay: number, attempt: number, lastError: Error }): false | any:

  • make one argument meta, with 4 properties (it allows to add more props in future without care of its order)
  • if this method returns false then abort requests, otherwise for any other returned value (even null, undefined) middleware should continue requests.

forceRetry is unobvious and looks like some piece of 💩 BUT forceRetry needs to leave as is for backward compatibility and mark as DEPRECATED in readme.md.

Also, do you want me to only handle the Network request failed error or all error that do not contain a response from the server as it is now.

For now, I don't know what behavior will be better. So do it according to your real use cases.

@ntelkedzhiev
Copy link
Contributor Author

Sounds good! Thanks for the suggestions! Will do.

@ntelkedzhiev
Copy link
Contributor Author

ntelkedzhiev commented Sep 17, 2018

@nodkz When I run yarn test I get:

Requires Babel "^7.0.0-0", but was loaded with "6.26.3". If you are sure you have a compatible version of @babel/core, it is likely that something in your build process is loading the wrong version. Inspect the stack trace of this error to look for the first entry that doesn't mention "@babel/core" or "babel-core" to see what is calling Babel.

Any idea why?

@nodkz
Copy link
Collaborator

nodkz commented Sep 17, 2018

It's very strange.
Try to remove node_modules folder and install packages from scratch yarn install:

rm -r ./node_modules
yarn install

@ntelkedzhiev
Copy link
Contributor Author

ntelkedzhiev commented Sep 17, 2018

I'm now getting:

 Jest encountered an unexpected token
  ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){
import fetchMock from 'fetch-mock';
^^^^^^
SyntaxError: Unexpected token import

@nodkz
Copy link
Collaborator

nodkz commented Sep 17, 2018

I have just clone your repo, and all works good on MacOS:

git clone git@github.com:ntelkedzhiev/react-relay-network-modern.git ./_fork_rrnm

yarn install 
# it returns some warnings with `fsevents`, but just ommit them

yarn test
# returns following output

screen shot 2018-09-17 at 19 40 55

What operation system do you use?

@nodkz
Copy link
Collaborator

nodkz commented Sep 17, 2018

What operation system do you use?


Your error looks like that babel was resolved incorrectly by node.

Maybe you have globally installed babel?
Try to remove it

npm uninstall -g babel
npm uninstall -g babel-cli
npm uninstall -g jest

@ntelkedzhiev
Copy link
Contributor Author

ntelkedzhiev commented Sep 17, 2018

Very weird. No, I don't have any of the babel/jest packages globally installed. Tried it on two Macs - running node 9.11.2 and 10.10.0 and it didn't work. Not sure how to fix this. What version of node are you running?

I also don't get any fsevents errors.

@nodkz
Copy link
Collaborator

nodkz commented Sep 17, 2018

What yarn version do you use?

yarn --version

Mine is 1.7.0

Just updated to the latest version 1.9.4

curl -o- -L https://yarnpkg.com/install.sh | bash

And try again it with your repo to run tests. And it works without babel error.

@nodkz
Copy link
Collaborator

nodkz commented Sep 17, 2018

If you update yarn, you'll need to remove node_modules folder and install packages again via yarn install.

@ntelkedzhiev
Copy link
Contributor Author

I'm running 1.9.4 as well.

@ntelkedzhiev
Copy link
Contributor Author

ntelkedzhiev commented Sep 17, 2018

Maybe this is needed: jestjs/jest#6053 (comment).


I am also able to successfully build which is weird too.

@nodkz
Copy link
Collaborator

nodkz commented Sep 17, 2018

Damn. First time met such problem.

Can you confirm that parent folders do not contain .babelrc files?
Maybe they somehow overrides settings from .babelrc in this repo?!

@ntelkedzhiev
Copy link
Contributor Author

Yes, no .babelrc files in parent folders.

@nodkz
Copy link
Collaborator

nodkz commented Sep 17, 2018

Just updated packages in master, can you merge this changes to your repo.

Tried to do it directly to your repo, but it looks like that you do not allow (remove checkbox when open PR) to send commits from maintainers/contributors.

After merging with master, it required to run yarn install for updating packages. Maybe it solves a problem, maybe not.

@ntelkedzhiev
Copy link
Contributor Author

ntelkedzhiev commented Sep 18, 2018

@nodkz Didn't have success after you pushed the changes. I added babel.config.js (and removed .babelrc) as documented here: https://github.com/facebook/jest/blob/master/docs/GettingStarted.md#using-babel.


Also fixed the error so PR is ready to merge. Let me know what you want to do with the babel issue since it is included in this PR and whether you want me to make any further changes.

@nodkz
Copy link
Collaborator

nodkz commented Sep 18, 2018

Please return back all babel configs, they are required for package building for the different environments.

Just copy all content from https://github.com/relay-tools/react-relay-network-modern/blob/master/.babelrc to babel.config.js.

@nodkz
Copy link
Collaborator

nodkz commented Sep 18, 2018

This code has some bug in tests.

When running tests in watch mode:

yarn watch

and re-run tests several times, it sometimes throws an error, sometimes pass.

It's a very strange behavior. Try to review it tomorrow.

@nodkz
Copy link
Collaborator

nodkz commented Sep 18, 2018

and I also think that the code is dirty and middlewate should be completely refactored.

Killed about 1 hour on testing and understanding what happens. It's bad sign.

@ntelkedzhiev
Copy link
Contributor Author

ntelkedzhiev commented Sep 19, 2018

Agreed. It needs to be rewritten. I'll submit a reworked PR next week.

@nodkz
Copy link
Collaborator

nodkz commented Sep 19, 2018

In progress right now

@nodkz
Copy link
Collaborator

nodkz commented Sep 19, 2018

@ntelkedzhiev Done. Please test it with your app.

NOTABLE CHANGE: Property onRetry was renamed to beforeRetry. It's a better name because it allows to abort following retry or run it immediately.

  1. Pull latest changes from ntelkedzhiev/react-relay-network-modern
  2. Run
yarn build
  1. Copy generated lib, es, mjs, node8 folders to your app's node_modules/react-relay-network-modern folder.
  2. Launch your app

@nodkz nodkz merged commit 47806aa into relay-tools:master Sep 19, 2018
@nodkz
Copy link
Collaborator

nodkz commented Sep 19, 2018

My coworkers tested the new version with their app. All works well.
So you may try the published version from npm and if you find an error, please let me know.

Thanks for your help!

@nodkz
Copy link
Collaborator

nodkz commented Sep 19, 2018

🎉 This PR is included in version 2.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@ntelkedzhiev
Copy link
Contributor Author

@nodkz Great! Thanks a lot man!

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

Successfully merging this pull request may close these issues.

2 participants