Skip to content

beforeRetry hook not receiving context from options.context #1141

@nrajkum2-uiuc

Description

@nrajkum2-uiuc

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething does not work as it should

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions