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

the request won't break even on throwing error #43

Open
mhamri opened this issue Aug 6, 2021 · 5 comments
Open

the request won't break even on throwing error #43

mhamri opened this issue Aug 6, 2021 · 5 comments

Comments

@mhamri
Copy link

mhamri commented Aug 6, 2021

I'm testing this addon out and I see that even throwing error wont' break fetch

throw `can't connect`;
return `{"error":"can't connect"}` ;

image

1- how to change response body?
2- how to change response code and cause an error?
3- how to correctly log, since I can't see the throw message in the console

@dangkyokhoang
Copy link
Owner

Your code should work. Just make sure the URL filters match the requests you're going to modify.

Altering response:
Man in the Middle - Modify response
Man in the Middle - Modify response

And logging:
Man in the Middle - Modify request
Man in the Middle - Modify request

@mhamri
Copy link
Author

mhamri commented Aug 7, 2021

for the example you've provided, as you can see in the image below, throw doesn't show any message in the console

image

image

if i have only this it works just fine

return `can't connect` ;

image

and as I mentioned in the first post, if I throw an error, even if I don't see the error in the console for some reason why still the page load? my expectation is to see the error or page not found or some other error

image

@dangkyokhoang
Copy link
Owner

for the example you've provided, as you can see in the image below, throw doesn't show any message in the console

Errors are logged to the extension's console, not the target pages'.

and as I mentioned in the first post, if I throw an error, even if I don't see the error in the console for some reason why still the page load? my expectation is to see the error or page not found or some other error

This is by design. Scripts modify responses, and when they fail to (i.e: when they throw an error), the responses should not be touched.

In case you want to display some error message when your script throws, just wrap it with a try catch.

@mhamri
Copy link
Author

mhamri commented Aug 9, 2021

thanks for response,

how do you open extensions dev tools? i couldn't find an easy way to open it (i managed to open it, but still want to know how do you suggest)

I also wanted to set status code to 501, do you have any suggestion how to do it?

@dangkyokhoang
Copy link
Owner

how do you open extensions dev tools? i couldn't find an easy way to open it (i managed to open it, but still want to know how do you suggest)

Errors are logged to the extension's Options page's console to be precise.

I also wanted to set status code to 501, do you have any suggestion how to do it?

There doesn't seem a way to change status codes. You can try altering headers and responses or redirecting requests to your custom server to see if it works.

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