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

TypeError: Cannot read properties of null (reading 'status') at SSE._onStreamFailure #74

Closed
vojtabohm opened this issue Jul 19, 2024 · 5 comments
Assignees
Labels

Comments

@vojtabohm
Copy link

This error happens when the connection to a server is refused. For example if you don't have proper CSP or the server just refuses.

In the method:

this._onStreamFailure = function(e) {
    const event = new CustomEvent('error');
    event.responseCode = this.xhr.status;
    event.data = e.currentTarget.response;
    this.dispatchEvent(event);
    this._markClosed();
  }

The xhr object seems to be null:
at SSE._onStreamFailure (webpack-internal:///./node_modules/sse.js/lib/sse.js:155:35)

@mpetazzoni
Copy link
Owner

Thanks for reporting! I'll take a look 👀

@mpetazzoni mpetazzoni added the bug label Jul 19, 2024
@mpetazzoni mpetazzoni self-assigned this Jul 19, 2024
@vojtabohm
Copy link
Author

Thank you for such a quick fix, man! 🫡

@vojtabohm
Copy link
Author

Could I ask, how can I try-catch this in my codebase? I am trying to wrap the entire EventSource creation + callback setup in a try catch but when this library fails (reading .status on a null object) it still is thrown as a runtime exception and I cannot gracefully fail in the UI.

@mpetazzoni

@mpetazzoni
Copy link
Owner

You might be able to do that with https://developer.mozilla.org/en-US/docs/Web/API/Window/error_event ?

@vojtabohm
Copy link
Author

vojtabohm commented Jul 25, 2024

You're right, I am able to catch it with that :) Thanks! Now it's about stopping the propagation inside Electron so it doesn't appear to the user. But I understand this is out of scope of this repo. If anyone knows how to do this, please let me know.

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

No branches or pull requests

2 participants