How to count Bad Handshake (WebSocket)?

Hello everyone!
Currently i’m working on the loadtest for websocket, then I got so much errors like this

Can I count how many the errors like that occurs in k6 report? Because the only checks is on 101 return status and the messages on websocket connection. Thank youu!!

Hi @gradito,

I am not certain I understood what you asked, but from the screenshot this looks like an exception(see the “source=stacktrace” at the end). This is a normal exception and is because welll … ws.connect totally didn’t manage to do anything of what you expected. I don’t know the exact reason for websocket: bad handshake but it is fairly easy to count exceptions - just wrap them in try-catch:

try {
// your ws.connect
// check for example
} catch(e) {
// here you can count it  ...  by for example increasing a Counter
// this code will get executed regardless if there was an exception 
// so you might want to do `throw e` in the catch if you don't want that 

I hope this helps you, and if I haven’t managed to understand what you asked for a small code sample might help me better understand what you are trying to do.

wow cool!
thanks @mstoykov
i will let u know if it works! thank youuu

it really works!!

I made a counter to count how many bad handshake occurs

thank youu!!

1 Like