Net/Exceptions/NetworkException.cs
using Sandbox;
using System;

namespace ExtendedBox.Net.Exceptions;

public class NetworkException : Exception
{
    public NetworkException(string message) : base(message)
    {

    }


    public static void ThrowOnRpcCaller(Exception exception) => ThrowRemotely(Rpc.Caller, exception);
    public static void ThrowRemotely(Connection connection, Exception exception)
    {
        NoAuthorityException.ThrowIfNotHost();
        if(connection == Connection.Local)
            throw new NetworkException($"Remote exception (from local): {exception}.");
        else
            CallThrowRemotely(connection.Id, $"Remote exception: {exception}.");
    }


    [Rpc.Broadcast(NetFlags.Reliable | NetFlags.HostOnly)]
    private static void CallThrowRemotely(Guid connectionId, string message)
    {
        if(Connection.Local.Id == connectionId)
            throw new NetworkException(message);
    }
}