Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle errors in the interceptor handler #437

Closed
Tracked by #2517
mikicho opened this issue Sep 21, 2023 · 4 comments
Closed
Tracked by #2517

Handle errors in the interceptor handler #437

mikicho opened this issue Sep 21, 2023 · 4 comments

Comments

@mikicho
Copy link
Contributor

mikicho commented Sep 21, 2023

Following this comment.

Problem: this line throws when an error occurs in the handler.
This prevents the user from handling errors with error listener in the request, which causes this test to fail.

I think it's because we currently don't catch the promise, we only handle the then case.

@kettanaito
Copy link
Member

Hi. Have you tried using Response.error() instead of throwing in the request listener?

until() works as try/catch so exceptions in its closure will also propagate to the .then() callback as result.error.

@mikicho
Copy link
Contributor Author

mikicho commented Sep 21, 2023

Hi. Have you tried using Response.error() instead of throwing in the request listener?

Yes, it converts the error to a generic Network error, which is not what we are after.

until() works as try/catch so exceptions in its closure will also propagate to the .then() callback as result.error.

Interesting, this is not what I see, the code never gets to the then clause, I'll try to reproduce it in a small script without Nock's noise.

@mikicho
Copy link
Contributor Author

mikicho commented Sep 21, 2023

Update: it seems like it's working as expected when I isolated the scenario in a small script.
I'll keep updating my findings and close this ticket if needed.

@mikicho
Copy link
Contributor Author

mikicho commented Sep 21, 2023

My mistake.
For reference, if you use a promise, reject it instead of throw an error:

interceptor.on('request', function ({ request, requestId }) {
  return new Promise((resolve, reject) => {
     throw error; // not working
     reject(error) // good
  })
}); 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants