diff --git a/README.md b/README.md index bdde200..301a0a2 100644 --- a/README.md +++ b/README.md @@ -203,9 +203,9 @@ Contributing is highly appreciated! #### What API layer is supported? The latest one - 57. Thanks to Afshin Arani for his TLGenerator -#### I get an error MIGRATE_X? +#### I get a xxxMigrationException or a MIGRATE_X error! -TLSharp library should automatically handle this errors. If you see such errors, pls create a new issue. +TLSharp library should automatically handle these errors. If you see such errors, please open a new Github issue with the details (include a stacktrace, etc.). #### I get an exception: System.IO.EndOfStreamException: Unable to read beyond the end of the stream. All test methos except that AuthenticationWorks and TestConnection return same error. I did every thing including setting api id and hash, and setting server address.- diff --git a/TLSharp.Core/Network/MtProtoSender.cs b/TLSharp.Core/Network/MtProtoSender.cs index 1f22aeb..d46a68e 100644 --- a/TLSharp.Core/Network/MtProtoSender.cs +++ b/TLSharp.Core/Network/MtProtoSender.cs @@ -279,7 +279,7 @@ namespace TLSharp.Core.Network { var resultString = Regex.Match(errorMessage, @"\d+").Value; var dcIdx = int.Parse(resultString); - throw new MigrationNeededException(dcIdx); + throw new PhoneMigrationException(dcIdx); } else if (errorMessage.StartsWith("FILE_MIGRATE_")) { @@ -495,36 +495,40 @@ namespace TLSharp.Core.Network } } - internal class MigrationNeededException : Exception + internal abstract class DataCenterMigrationException : Exception { internal int DC { get; private set; } - internal MigrationNeededException(int dc) - : base ($"Your phone number is registered to a different DC: {dc}. Please migrate.") + 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 FileMigrationException : Exception + internal class PhoneMigrationException : DataCenterMigrationException { - internal int DC { get; private set; } + internal PhoneMigrationException(int dc) + : base ($"Phone number registered to a different DC: {dc}.", dc) + { + } + } + internal class FileMigrationException : DataCenterMigrationException + { internal FileMigrationException(int dc) - : base ($"File is located on a different DC: {dc}. Please migrate.") + : base ($"File located on a different DC: {dc}.", dc) { - DC = dc; } } - internal class UserMigrationException : Exception + internal class UserMigrationException : DataCenterMigrationException { - internal int DC { get; private set; } - internal UserMigrationException(int dc) - : base($"User is located on a different DC: {dc}. Please migrate.") + : base($"User located on a different DC: {dc}.", dc) { - DC = dc; } } } \ No newline at end of file diff --git a/TLSharp.Core/TelegramClient.cs b/TLSharp.Core/TelegramClient.cs index 0c6f3c7..03083f4 100644 --- a/TLSharp.Core/TelegramClient.cs +++ b/TLSharp.Core/TelegramClient.cs @@ -124,7 +124,7 @@ namespace TLSharp.Core completed = true; } - catch (MigrationNeededException ex) + catch (PhoneMigrationException ex) { await ReconnectToDcAsync(ex.DC); }