Merge pull request #272 from knocte/reworkMigrateExceptions

Rework MIGRATE errors/exceptions
This commit is contained in:
Ilya Pirozhenko 2016-10-30 11:51:30 +03:00 committed by GitHub
commit b0b58be25e
3 changed files with 20 additions and 16 deletions

View file

@ -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.-

View file

@ -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;
}
}
}

View file

@ -124,7 +124,7 @@ namespace TLSharp.Core
completed = true;
}
catch (MigrationNeededException ex)
catch (PhoneMigrationException ex)
{
await ReconnectToDcAsync(ex.DC);
}