-
-
Notifications
You must be signed in to change notification settings - Fork 969
Closed
Labels
bugSomething does not work as it shouldSomething does not work as it should
Description
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
})
}
]
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
})
}
]
Checklist
- I have read the documentation.
- I have tried my code with the latest version of Node.js and Got.
Metadata
Metadata
Assignees
Labels
bugSomething does not work as it shouldSomething does not work as it should