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 }
The hook beforeRetry is not getting the context from the options passed into it. options.context is {}.
...
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.
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
})
}
]

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
})
}
]

Could you set up a full RunKit example? Please check out 11.0.0-beta.1 as it has fixed many issues.
https://runkit.com/nrajkum2-uiuc/got-library-error
Here you go!
Thank you for the example, indeed this is a bug. Will work on this today.
Fixed in 0fbc3907f452fad9123d9339d1935e7a1ded297f