mirror of
https://github.com/sochix/TLSharp.git
synced 2025-12-06 08:02:00 +01:00
Add proper exception messages
This commit is contained in:
parent
27216da193
commit
b0a824988d
|
|
@ -267,6 +267,12 @@ namespace TLSharp.Core.Network
|
||||||
Debug.WriteLine($"Should wait {seconds} sec.");
|
Debug.WriteLine($"Should wait {seconds} sec.");
|
||||||
Thread.Sleep(1000*seconds);
|
Thread.Sleep(1000*seconds);
|
||||||
}
|
}
|
||||||
|
else if (errorMessage.StartsWith("PHONE_MIGRATE_"))
|
||||||
|
{
|
||||||
|
var resultString = Regex.Match(errorMessage, @"\d+").Value;
|
||||||
|
var dcIdx = int.Parse(resultString);
|
||||||
|
throw new InvalidOperationException($"Your phone number registered to {dcIdx} dc. Please update settings. See https://github.com/sochix/TLSharp#i-get-an-error-migrate_x for details.");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(errorMessage);
|
throw new InvalidOperationException(errorMessage);
|
||||||
|
|
@ -332,7 +338,7 @@ namespace TLSharp.Core.Network
|
||||||
throw new InvalidOperationException("invalid container");
|
throw new InvalidOperationException("invalid container");
|
||||||
|
|
||||||
}
|
}
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException("This should never happens");
|
||||||
/*
|
/*
|
||||||
logger.debug("bad_msg_notification: msgid {0}, seq {1}, errorcode {2}", requestId, requestSequence,
|
logger.debug("bad_msg_notification: msgid {0}, seq {1}, errorcode {2}", requestId, requestSequence,
|
||||||
errorCode);
|
errorCode);
|
||||||
|
|
@ -397,7 +403,7 @@ namespace TLSharp.Core.Network
|
||||||
|
|
||||||
messageReader.BaseStream.Position -= 12;
|
messageReader.BaseStream.Position -= 12;
|
||||||
|
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException("Handle future server salts function isn't implemented.");
|
||||||
/*
|
/*
|
||||||
if (!runningRequests.ContainsKey(requestId))
|
if (!runningRequests.ContainsKey(requestId))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -14,12 +14,18 @@ namespace TLSharp.Core
|
||||||
private MtProtoSender _sender;
|
private MtProtoSender _sender;
|
||||||
private AuthKey _key;
|
private AuthKey _key;
|
||||||
private readonly TcpTransport _transport;
|
private readonly TcpTransport _transport;
|
||||||
private string _apiHash = "_your_hash";
|
private string _apiHash = "a2514f96431a228e4b9ee473f6c51945";
|
||||||
private int _apiId = 0;
|
private int _apiId = 19474;
|
||||||
private Session _session;
|
private Session _session;
|
||||||
|
|
||||||
public TelegramClient(ISessionStore store, string sessionUserId)
|
public TelegramClient(ISessionStore store, string sessionUserId)
|
||||||
{
|
{
|
||||||
|
if (_apiId == 0)
|
||||||
|
throw new InvalidOperationException("Your API_ID is invalid. Do a configuration first https://github.com/sochix/TLSharp#quick-configuration");
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(_apiHash))
|
||||||
|
throw new InvalidOperationException("Your API_ID is invalid. Do a configuration first https://github.com/sochix/TLSharp#quick-configuration");
|
||||||
|
|
||||||
_transport = new TcpTransport();
|
_transport = new TcpTransport();
|
||||||
_session = Session.TryLoadOrCreateNew(store, sessionUserId);
|
_session = Session.TryLoadOrCreateNew(store, sessionUserId);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,22 @@ namespace TLSharp.Tests
|
||||||
{
|
{
|
||||||
// Setup your phone numbers in app.config
|
// Setup your phone numbers in app.config
|
||||||
NumberToAuthenticate = ConfigurationManager.AppSettings["numberToAuthenticate"];
|
NumberToAuthenticate = ConfigurationManager.AppSettings["numberToAuthenticate"];
|
||||||
|
if (string.IsNullOrEmpty(NumberToAuthenticate))
|
||||||
|
throw new InvalidOperationException("NumberToAuthenticate is null");
|
||||||
|
|
||||||
RegisteredNumber = ConfigurationManager.AppSettings["registeredNumber"];
|
RegisteredNumber = ConfigurationManager.AppSettings["registeredNumber"];
|
||||||
|
if (string.IsNullOrEmpty(RegisteredNumber))
|
||||||
|
throw new InvalidOperationException("RegisteredNumber is null");
|
||||||
|
|
||||||
UnregisteredNumber = ConfigurationManager.AppSettings["unregisteredNumber"];
|
UnregisteredNumber = ConfigurationManager.AppSettings["unregisteredNumber"];
|
||||||
|
if (string.IsNullOrEmpty(UnregisteredNumber))
|
||||||
|
throw new InvalidOperationException("UnregisteredNumber is null");
|
||||||
|
|
||||||
|
if (NumberToAuthenticate == UnregisteredNumber)
|
||||||
|
throw new InvalidOperationException("NumberToAuthenticate eqauls UnregisteredNumber but shouldn't!");
|
||||||
|
|
||||||
|
if (RegisteredNumber == UnregisteredNumber)
|
||||||
|
throw new InvalidOperationException("RegisteredNumber eqauls UnregisteredNumber but shouldn't!");
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
|
|
@ -30,6 +44,7 @@ namespace TLSharp.Tests
|
||||||
{
|
{
|
||||||
var store = new FileSessionStore();
|
var store = new FileSessionStore();
|
||||||
var client = new TelegramClient(store, "session");
|
var client = new TelegramClient(store, "session");
|
||||||
|
|
||||||
await client.Connect();
|
await client.Connect();
|
||||||
|
|
||||||
var hash = await client.SendCodeRequest(NumberToAuthenticate);
|
var hash = await client.SendCodeRequest(NumberToAuthenticate);
|
||||||
|
|
@ -70,6 +85,7 @@ namespace TLSharp.Tests
|
||||||
|
|
||||||
var store = new FileSessionStore();
|
var store = new FileSessionStore();
|
||||||
var client = new Core.TelegramClient(store, "session");
|
var client = new Core.TelegramClient(store, "session");
|
||||||
|
|
||||||
await client.Connect();
|
await client.Connect();
|
||||||
|
|
||||||
Assert.IsTrue(client.IsUserAuthorized());
|
Assert.IsTrue(client.IsUserAuthorized());
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue