mirror of
https://github.com/sochix/TLSharp.git
synced 2026-04-20 22:05:10 +00:00
Some generic exceptions refactored into custom and specific exceptions
This commit is contained in:
parent
f6ef04ed01
commit
2687057ff0
2 changed files with 51 additions and 3 deletions
|
|
@ -110,7 +110,7 @@ namespace TLSharp.Core.Network
|
||||||
using (var inputReader = new BinaryReader(inputStream))
|
using (var inputReader = new BinaryReader(inputStream))
|
||||||
{
|
{
|
||||||
if (inputReader.BaseStream.Length < 8)
|
if (inputReader.BaseStream.Length < 8)
|
||||||
throw new InvalidOperationException($"Can't decode packet");
|
throw new DecodePacketException();
|
||||||
|
|
||||||
ulong remoteAuthKeyId = inputReader.ReadUInt64(); // TODO: check auth key id
|
ulong remoteAuthKeyId = inputReader.ReadUInt64(); // TODO: check auth key id
|
||||||
byte[] msgKey = inputReader.ReadBytes(16); // TODO: check msg_key correctness
|
byte[] msgKey = inputReader.ReadBytes(16); // TODO: check msg_key correctness
|
||||||
|
|
@ -313,6 +313,15 @@ namespace TLSharp.Core.Network
|
||||||
{
|
{
|
||||||
throw new CloudPasswordNeededException("This Account has Cloud Password !");
|
throw new CloudPasswordNeededException("This Account has Cloud Password !");
|
||||||
}
|
}
|
||||||
|
else if (errorMessage == "AUTH_KEY_UNREGISTERED")
|
||||||
|
{
|
||||||
|
//
|
||||||
|
throw new AuthKeyUnregisteredException();
|
||||||
|
}
|
||||||
|
else if (errorMessage == "RPC_MCGET_FAIL")
|
||||||
|
{
|
||||||
|
throw new RpcMcGetFailException();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(errorMessage);
|
throw new InvalidOperationException(errorMessage);
|
||||||
|
|
@ -535,6 +544,29 @@ namespace TLSharp.Core.Network
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class DecodePacketException : Exception
|
||||||
|
{
|
||||||
|
internal DecodePacketException() : base($"Can't decode packet.")
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class AuthKeyUnregisteredException : Exception
|
||||||
|
{
|
||||||
|
internal AuthKeyUnregisteredException() : base($"Auth key is unregistered.")
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class RpcMcGetFailException : Exception
|
||||||
|
{
|
||||||
|
internal RpcMcGetFailException() : base($"Rpc Mc Get Fail.")
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
internal abstract class DataCenterMigrationException : Exception
|
internal abstract class DataCenterMigrationException : Exception
|
||||||
{
|
{
|
||||||
internal int DC { get; private set; }
|
internal int DC { get; private set; }
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ namespace TLSharp.Core.Network
|
||||||
public async Task Send(byte[] packet)
|
public async Task Send(byte[] packet)
|
||||||
{
|
{
|
||||||
if (!_tcpClient.Connected)
|
if (!_tcpClient.Connected)
|
||||||
throw new InvalidOperationException("Client not connected to server.");
|
throw new TcpClientNotConnectedException();
|
||||||
|
|
||||||
var tcpMessage = new TcpMessage(sendCounter, packet);
|
var tcpMessage = new TcpMessage(sendCounter, packet);
|
||||||
|
|
||||||
|
|
@ -42,7 +42,7 @@ namespace TLSharp.Core.Network
|
||||||
|
|
||||||
var packetLengthBytes = new byte[4];
|
var packetLengthBytes = new byte[4];
|
||||||
if (await stream.ReadAsync(packetLengthBytes, 0, 4) != 4)
|
if (await stream.ReadAsync(packetLengthBytes, 0, 4) != 4)
|
||||||
throw new InvalidOperationException("Couldn't read the packet length");
|
throw new TcpClientCouldntReadPacketLengthException();
|
||||||
int packetLength = BitConverter.ToInt32(packetLengthBytes, 0);
|
int packetLength = BitConverter.ToInt32(packetLengthBytes, 0);
|
||||||
|
|
||||||
var seqBytes = new byte[4];
|
var seqBytes = new byte[4];
|
||||||
|
|
@ -92,4 +92,20 @@ namespace TLSharp.Core.Network
|
||||||
_tcpClient.Close();
|
_tcpClient.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public class TcpClientNotConnectedException : Exception
|
||||||
|
{
|
||||||
|
internal TcpClientNotConnectedException() : base($"Client not connected to server.")
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class TcpClientCouldntReadPacketLengthException : Exception
|
||||||
|
{
|
||||||
|
internal TcpClientCouldntReadPacketLengthException() : base($"Couldn't read the packet length")
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue