I would like to instrument a Got instance using beforeRequest, afterResponse and beforeError hooks. The plan is to create a new request context for each request in the beforeRequest hook and then access that context in the afterResponse and beforeError hooks to report the request's success/error status.
The natural way to do this would be to just mutate the options object in beforeRequest and set a new property containing the context, this is easy to access in both afterResponse and beforeError through the gotOptions given. My only worry is that by introducing new properties in the options there might be incompatibilities with other hooks or later versions of Got itself.
Are there any guidelines or rules of how to name custom variables inside options? Or alternatively is there any better place where I could store my custom property? I plan to release my instrumentation as a public library, so I just want to confirm that I'm not doing anything wrong here.
IssueHunt Summary
#
#
#
#
[
<
i
m
g
s
r
'
h
t
t
p
s
:
/
/
a
v
a
t
a
r
s
0
.
g
i
t
h
u
b
u
s
e
r
c
o
n
t
e
n
t
.
c
o
m
/
u
/
3
6
8
9
4
7
0
0
?
4
'
a
l
'
s
z
m
a
r
c
z
a
k
'
w
i
d
t
2
4
h
e
i
g
h
2
4
>
s
z
m
a
r
c
z
a
k
]
(
h
t
t
p
s
:
/
/
i
s
s
u
e
h
u
n
t
.
i
o
/
u
/
s
z
m
a
r
c
z
a
k
)
h
a
s
b
e
e
n
r
e
w
a
r
d
e
d
.
userData optionIssueHunt has been backed by the following sponsors. Become a sponsor
~You can use Symbols.~
It won't work because the options are cloned. We need to discuss possible solutions.
I think the best would be to use a prefix. Like:
options._myAppData = context;
We should document this.
Thank you for the quick response, I will go with the underscore prefix.
@szmarczak How about we just support a custom option where users can put whatever they want? userData?
@sindresorhus Sounds good! Also it shouldn't be enumerable by default I think...
Agreed
@issuehunt has funded $60.00 to this issue.
@sindresorhus has rewarded $54.00 to @szmarczak. See it on IssueHunt
Most helpful comment
We should document this.