diff --git a/TLSharp.Core/Exceptions/CloudPasswordNeededException.cs b/TLSharp.Core/Exceptions/CloudPasswordNeededException.cs new file mode 100644 index 0000000..cf6e222 --- /dev/null +++ b/TLSharp.Core/Exceptions/CloudPasswordNeededException.cs @@ -0,0 +1,9 @@ +using System; + +namespace TLSharp.Core.Exceptions +{ + public class CloudPasswordNeededException : Exception + { + internal CloudPasswordNeededException(string msg) : base(msg) { } + } +} \ No newline at end of file diff --git a/TLSharp.Core/Exceptions/InvalidPhoneCodeException.cs b/TLSharp.Core/Exceptions/InvalidPhoneCodeException.cs new file mode 100644 index 0000000..bb8a52d --- /dev/null +++ b/TLSharp.Core/Exceptions/InvalidPhoneCodeException.cs @@ -0,0 +1,9 @@ +using System; + +namespace TLSharp.Core.Exceptions +{ + public class InvalidPhoneCodeException : Exception + { + internal InvalidPhoneCodeException(string msg) : base(msg) { } + } +} \ No newline at end of file diff --git a/TLSharp.Core/Exceptions/MissingApiConfigurationException.cs b/TLSharp.Core/Exceptions/MissingApiConfigurationException.cs new file mode 100644 index 0000000..26ce94e --- /dev/null +++ b/TLSharp.Core/Exceptions/MissingApiConfigurationException.cs @@ -0,0 +1,14 @@ +using System; + +namespace TLSharp.Core.Exceptions +{ + public class MissingApiConfigurationException : Exception + { + public const string InfoUrl = "https://github.com/sochix/TLSharp#quick-configuration"; + + internal MissingApiConfigurationException(string invalidParamName) : + base($"Your {invalidParamName} setting is missing. Adjust the configuration first, see {InfoUrl}") + { + } + } +} \ No newline at end of file diff --git a/TLSharp.Core/Network/Exceptions/DataCenterMigrationException.cs b/TLSharp.Core/Network/Exceptions/DataCenterMigrationException.cs new file mode 100644 index 0000000..b80d4a1 --- /dev/null +++ b/TLSharp.Core/Network/Exceptions/DataCenterMigrationException.cs @@ -0,0 +1,17 @@ +using System; + +namespace TLSharp.Core.Network.Exceptions +{ + internal abstract class DataCenterMigrationException : Exception + { + internal int DC { get; private set; } + + private const string REPORT_MESSAGE = + " See: https://github.com/sochix/TLSharp#i-get-a-xxxmigrationexception-or-a-migrate_x-error"; + + protected DataCenterMigrationException(string msg, int dc) : base (msg + REPORT_MESSAGE) + { + DC = dc; + } + } +} \ No newline at end of file diff --git a/TLSharp.Core/Network/Exceptions/FileMigrationException.cs b/TLSharp.Core/Network/Exceptions/FileMigrationException.cs new file mode 100644 index 0000000..21e8211 --- /dev/null +++ b/TLSharp.Core/Network/Exceptions/FileMigrationException.cs @@ -0,0 +1,10 @@ +namespace TLSharp.Core.Network.Exceptions +{ + internal class FileMigrationException : DataCenterMigrationException + { + internal FileMigrationException(int dc) + : base ($"File located on a different DC: {dc}.", dc) + { + } + } +} \ No newline at end of file diff --git a/TLSharp.Core/Network/Exceptions/FloodException.cs b/TLSharp.Core/Network/Exceptions/FloodException.cs new file mode 100644 index 0000000..be6407c --- /dev/null +++ b/TLSharp.Core/Network/Exceptions/FloodException.cs @@ -0,0 +1,16 @@ +using System; + +namespace TLSharp.Core.Network.Exceptions +{ + public class FloodException : Exception + { + public TimeSpan TimeToWait { get; private set; } + + internal FloodException(TimeSpan timeToWait) + : base($"Flood prevention. Telegram now requires your program to do requests again only after {timeToWait.TotalSeconds} seconds have passed ({nameof(TimeToWait)} property)." + + " If you think the culprit of this problem may lie in TLSharp's implementation, open a Github issue please.") + { + TimeToWait = timeToWait; + } + } +} \ No newline at end of file diff --git a/TLSharp.Core/Network/Exceptions/NetworkMigrationException.cs b/TLSharp.Core/Network/Exceptions/NetworkMigrationException.cs new file mode 100644 index 0000000..7d20019 --- /dev/null +++ b/TLSharp.Core/Network/Exceptions/NetworkMigrationException.cs @@ -0,0 +1,10 @@ +namespace TLSharp.Core.Network.Exceptions +{ + internal class NetworkMigrationException : DataCenterMigrationException + { + internal NetworkMigrationException(int dc) + : base($"Network located on a different DC: {dc}.", dc) + { + } + } +} \ No newline at end of file diff --git a/TLSharp.Core/Network/Exceptions/PhoneMigrationException.cs b/TLSharp.Core/Network/Exceptions/PhoneMigrationException.cs new file mode 100644 index 0000000..f953687 --- /dev/null +++ b/TLSharp.Core/Network/Exceptions/PhoneMigrationException.cs @@ -0,0 +1,10 @@ +namespace TLSharp.Core.Network.Exceptions +{ + internal class PhoneMigrationException : DataCenterMigrationException + { + internal PhoneMigrationException(int dc) + : base ($"Phone number registered to a different DC: {dc}.", dc) + { + } + } +} \ No newline at end of file diff --git a/TLSharp.Core/Network/Exceptions/UserMigrationException.cs b/TLSharp.Core/Network/Exceptions/UserMigrationException.cs new file mode 100644 index 0000000..bbd55e2 --- /dev/null +++ b/TLSharp.Core/Network/Exceptions/UserMigrationException.cs @@ -0,0 +1,10 @@ +namespace TLSharp.Core.Network.Exceptions +{ + internal class UserMigrationException : DataCenterMigrationException + { + internal UserMigrationException(int dc) + : base($"User located on a different DC: {dc}.", dc) + { + } + } +} \ No newline at end of file diff --git a/TLSharp.Core/Network/MtProtoSender.cs b/TLSharp.Core/Network/MtProtoSender.cs index a0361a2..c8a613e 100644 --- a/TLSharp.Core/Network/MtProtoSender.cs +++ b/TLSharp.Core/Network/MtProtoSender.cs @@ -7,8 +7,10 @@ using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using Ionic.Zlib; +using TLSharp.Core.Exceptions; using TLSharp.Core.MTProto; using TLSharp.Core.MTProto.Crypto; +using TLSharp.Core.Network.Exceptions; using TLSharp.Core.Requests; using TLSharp.Core.Utils; @@ -523,61 +525,4 @@ namespace TLSharp.Core.Network return new MemoryStream(new byte[len], 0, len, true, true); } } - - public class FloodException : Exception - { - public TimeSpan TimeToWait { get; private set; } - - internal FloodException(TimeSpan timeToWait) - : base($"Flood prevention. Telegram now requires your program to do requests again only after {timeToWait.TotalSeconds} seconds have passed ({nameof(TimeToWait)} property)." + - " If you think the culprit of this problem may lie in TLSharp's implementation, open a Github issue please.") - { - TimeToWait = timeToWait; - } - } - - internal abstract class DataCenterMigrationException : Exception - { - internal int DC { get; private set; } - - private const string REPORT_MESSAGE = - " See: https://github.com/sochix/TLSharp#i-get-a-xxxmigrationexception-or-a-migrate_x-error"; - - protected DataCenterMigrationException(string msg, int dc) : base (msg + REPORT_MESSAGE) - { - DC = dc; - } - } - - internal class PhoneMigrationException : DataCenterMigrationException - { - internal PhoneMigrationException(int dc) - : base ($"Phone number registered to a different DC: {dc}.", dc) - { - } - } - - internal class FileMigrationException : DataCenterMigrationException - { - internal FileMigrationException(int dc) - : base ($"File located on a different DC: {dc}.", dc) - { - } - } - - internal class UserMigrationException : DataCenterMigrationException - { - internal UserMigrationException(int dc) - : base($"User located on a different DC: {dc}.", dc) - { - } - } - - internal class NetworkMigrationException : DataCenterMigrationException - { - internal NetworkMigrationException(int dc) - : base($"Network located on a different DC: {dc}.", dc) - { - } - } } diff --git a/TLSharp.Core/TLSharp.Core.csproj b/TLSharp.Core/TLSharp.Core.csproj index 74efe73..237eccb 100644 --- a/TLSharp.Core/TLSharp.Core.csproj +++ b/TLSharp.Core/TLSharp.Core.csproj @@ -48,6 +48,9 @@ + + + @@ -57,10 +60,16 @@ + + + + + + diff --git a/TLSharp.Core/TelegramClient.cs b/TLSharp.Core/TelegramClient.cs index ffc334c..7dad81a 100644 --- a/TLSharp.Core/TelegramClient.cs +++ b/TLSharp.Core/TelegramClient.cs @@ -12,8 +12,10 @@ using TeleSharp.TL.Help; using TeleSharp.TL.Messages; using TeleSharp.TL.Upload; using TLSharp.Core.Auth; +using TLSharp.Core.Exceptions; using TLSharp.Core.MTProto.Crypto; using TLSharp.Core.Network; +using TLSharp.Core.Network.Exceptions; using TLSharp.Core.Utils; using TLAuthorization = TeleSharp.TL.Auth.TLAuthorization; @@ -446,23 +448,4 @@ namespace TLSharp.Core } } } - - public class MissingApiConfigurationException : Exception - { - public const string InfoUrl = "https://github.com/sochix/TLSharp#quick-configuration"; - - internal MissingApiConfigurationException(string invalidParamName) : - base($"Your {invalidParamName} setting is missing. Adjust the configuration first, see {InfoUrl}") - { - } - } - - public class InvalidPhoneCodeException : Exception - { - internal InvalidPhoneCodeException(string msg) : base(msg) { } - } - public class CloudPasswordNeededException : Exception - { - internal CloudPasswordNeededException(string msg) : base(msg) { } - } } diff --git a/TLSharp.Tests/TLSharpTests.cs b/TLSharp.Tests/TLSharpTests.cs index 34bca76..3fc05ca 100644 --- a/TLSharp.Tests/TLSharpTests.cs +++ b/TLSharp.Tests/TLSharpTests.cs @@ -10,7 +10,9 @@ using System.Threading.Tasks; using TeleSharp.TL; using TeleSharp.TL.Messages; using TLSharp.Core; +using TLSharp.Core.Exceptions; using TLSharp.Core.Network; +using TLSharp.Core.Network.Exceptions; using TLSharp.Core.Requests; using TLSharp.Core.Utils;