Error check for closing the websocket