Error Handling in UNET

how can I get the error text and code in unity networking,?

I did the following:
1- subscribe to the Handler : Client.RegisterHandler(MsgType.Error, OnError);
2- create the handler
void OnError(NetworkMessage netMsg)
{
how can I print the ERROR message here
}

Usually you would do something like:
ErrorMessageType errorMsg = netMsg.ReadMessage();

And then you could get at the information in that message. Though I can’t find any reference to the class Unity would associate with MsgType.Error. It’s possibly something they haven’t exposed. Other kinds of messages use a class we define ourselves ontop of MessageBase. Hopefully someone else knows more, as it sure would be useful to get at :smile:

Right… it is:

var errorMsg = netMsg.ReadMessage();

The errorCode member of ErrorMessage is the transport layer NetworkError code:

http://docs.unity3d.com/ScriptReference/Networking.NetworkError.html

It’s said ErrorMessage doesn’t contain in current context ?

1 Like

I have been trying to implement a function which upon failing to connect to the server takes the user to a different scene.
I have managed to implement the above code, and everything works fine, i can get the messages upon failing to connect.
But i just can’t make my code to do anything else(change the scene) instead of just delivering messages.

Any assistance would be highly appreciated…

I just ran across this, and it looks like it wasn’t resolved, and I suffered through the same problem.

You need to use UnityEngine.Networking.NetworkSystem:

using UnityEngine.Networking.NetworkSystem;

…

Debug.Log("Client: OnError: " + netMsg.ToString());
ErrorMessage mess = netMsg.ReadMessage ();
owner.OnGameError ("Failed to connect: " + ((NetworkError)mess.errorCode).ToString());

Why is mess.errorCode an int and not a NetworkError? Who knows?

Shaun

1 Like