Handles error when connecting to the server