# UNET Error handling

I am trying to handle errors received by a UNET (new Unity3D networking) client. The below code successfully connects to a server when it is present, but obviously gives a timeout error when there is no server present.

I am trying to determine which type of error was received by the OnError callback method. MsgType is equal to MsgType.Error, which isn't specific, and all of the Read functions I have tried do not return valid data. At minimum I would like to be able to print the same error that prints to the debug log in a location the player can see it.

public class TestClient: MonoBehavior {

private NetworkClient client;

void Start () {
client = new NetworkClient();
client.Connect("127.0.0.1", 1234);
client.RegisterHandler(MsgType.Error, OnError);
}

public void OnError(NetworkMessage netMsg) {

//Read netMsg here somehow

Debug.Log("Failed to connect to server");
}
}


Note: This code is a retyped copy the working code, so there might be a typo or twenty. It also takes 15-30 seconds to throw the error (I didn't time it).

netMsg.ReadMessage<ErrorMessage>();