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

beforeRetry hook not receiving context from options.context #1141

Closed
2 tasks done
nrajkum2-uiuc opened this issue Apr 1, 2020 · 4 comments
Closed
2 tasks done

beforeRetry hook not receiving context from options.context #1141

nrajkum2-uiuc opened this issue Apr 1, 2020 · 4 comments
Labels
bug Something does not work as it should

Comments

@nrajkum2-uiuc
Copy link

Describe the bug

  • Node.js version: 10.14.1
  • OS & version: MacOs 10.14.6

I'm trying to attach a logger to the context so that I can log certain messages before a retry of a request is performed. The context key in the options to got looks like this:
{ context: logger }

Actual behavior

The hook beforeRetry is not getting the context from the options passed into it. options.context is {}.
...

Expected behavior

I expect the beforeRetry hook to have the context object in the options.context parameter of its functions to be the same value which I passed in: { context: logger }.

...
I changed the hook to a beforeRequest and the context was passed through successfully.

Code to reproduce for failure

                beforeRetry: [
                    (options, error, retryCount) => {
                        const { context } = options
                        console.log(context)
                        context.logger.warn('--Redacted for privacy---', {
                            method: options.method,
                            path: options.url.pathname,
                            errorName: error.name,
                            errorMessage: error.message,
                            retryCount
                        })
                    }
                ]

image

Using beforeRequest hook worked

                beforeRequest: [
                    (options) => {
                        const { context } = options
                        console.log(context)
                        context.logger.warn('--Redacted for privacy---', {
                            method: options.method,
                            path: options.url.pathname,
                            // errorName: error.name,
                            // errorMessage: error.message,
                            // retryCount
                        })
                    }
                ]

image

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Got.
@szmarczak
Copy link
Collaborator

Could you set up a full RunKit example? Please check out 11.0.0-beta.1 as it has fixed many issues.

@nrajkum2-uiuc
Copy link
Author

https://runkit.com/nrajkum2-uiuc/got-library-error
Here you go!

@szmarczak szmarczak added the bug Something does not work as it should label Apr 12, 2020
@szmarczak
Copy link
Collaborator

Thank you for the example, indeed this is a bug. Will work on this today.

@szmarczak
Copy link
Collaborator

Fixed in 0fbc390

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something does not work as it should
Projects
None yet
Development

No branches or pull requests

2 participants