scratchyone / wasm-sockets

A rust WASM-specific websocket library
MIT License
31 stars 3 forks source link

Onerrror handler's argument should use `Event`, not `ErrorEvent` #7

Open ctm opened 3 months ago

ctm commented 3 months ago

EventClient::set_on_error should take a Option<Box<dyn Fn(Event)>>, not a Option<Box<dyn Fn(ErrorEvent)>>.

Calling any of the ErrorEvent specific methods (e.g., message) from within an onerror handler causes programs to die. Calling Event specific methods (e.g., type_, time_stamp) work fine. According to MDN, the type of the error event is "A generic Event".

FWIW, there's a chance that an ErrorEvent has been passed in the past, because I have some code from January 2022 that calls .message() that I think used to work. It's hard for me to be sure that it worked, because it's in error handling code that rarely gets called. I certainly would like to think that I'd have noticed it if it has been broken for two and a half years, but I can't guarantee that.