Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0428632
commit 1976a76
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1976a76
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interceptors seem to work slightly differently than in axios. Specifically, I can't get my response error interceptor to work.
On axios I did:
which added a response and an error interceptor.
Doing this with rapidjs like so doesn't seem to work:
The response interceptor is called for valid responses. However, it's not called when an error occurs. How am I supposed to add an error interceptor? I get that there's no documentation on it since it's a very recent change. Can you provide some insight on how to correctly define the interceptors?
1976a76
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mgred would you mind responding here?
1976a76
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I took a deep look at it and here's where the error is. When adding interceptors using plain axios like this:
you are calling a specific funtion that puts the two arguments into a specific 'handler' array as you can see here in line 17:
with the implementation you currently have in rapid.js, a reject handler cannot be added because here's what happens if you try:
the interceptors are just stored as a plain array. so for example if you want to put a response interceptor, you do:
this works fine for normal responses, but you have no way to add a handler for the response rejection, since you're just pushing functions onto the array.
this array is then used in the API initializiation like this:
see here (line 106)
the 'types' are just "request" and "response".
so:
types.forEach((type) => {
will do its body for each function inside the 'this.interceptors.response' array.so the body
this.api.interceptors[type].use(interceptor);
is always called with just a single argument, which is the funtion in the rapid's response interceptor array. this means you can never add a 'reject' argument.rapid.js should provide an interface that is similar to axios. maybe, it should have two 'InterceptorManager' Objects from axios named 'interceptors.request' and 'interceptors.response' instead of plain arrays.
Then in method 'writeInterceptorsToAPI' it should do:
1976a76
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@M3psipax Thanks for your very detailed report!
I totally agree here. I will open a new issue and change this regarding your proposals.
@drewjbartlett fyi
1976a76
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, awesome, thanks!
fyi my current workaround is to attach the interceptors to the underlying axios instance like this:
1976a76
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, thanks for sharing!
#43 is the related issue.