Пример #1
0
        private void HandleRpcError(long messageReqMsgId, TRpcError error)
        {
            // rpc_error

            Log.Warn($"Recieve error from server: {error.ErrorMessage}");

            Exception exception;

            switch (error.ErrorMessage)
            {
            case var floodMessage when floodMessage.StartsWith("FLOOD_WAIT_"):
                var floodMessageTime = Regex.Match(floodMessage, @"\d+").Value;

                var seconds = int.Parse(floodMessageTime);
                exception = new FloodException(TimeSpan.FromSeconds(seconds));
                break;

            case var phoneMigrate when phoneMigrate.StartsWith("PHONE_MIGRATE_"):
                var phoneMigrateDcNumber = Regex.Match(phoneMigrate, @"\d+").Value;

                var phoneMigrateDcIdx = int.Parse(phoneMigrateDcNumber);
                exception = new PhoneMigrationException(phoneMigrateDcIdx);
                break;

            case var fileMigrate when fileMigrate.StartsWith("FILE_MIGRATE_"):
                var fileMigrateDcNumber = Regex.Match(fileMigrate, @"\d+").Value;

                var fileMigrateDcIdx = int.Parse(fileMigrateDcNumber);
                exception = new FileMigrationException(fileMigrateDcIdx);
                break;

            case var userMigrate when userMigrate.StartsWith("USER_MIGRATE_"):
                var userMigrateDcNumber = Regex.Match(userMigrate, @"\d+").Value;

                var userMigrateDcIdx = int.Parse(userMigrateDcNumber);
                exception = new UserMigrationException(userMigrateDcIdx);
                break;

            case "PHONE_CODE_INVALID":
                exception = new InvalidPhoneCodeException("The numeric code used to authenticate does not match the numeric code sent by SMS/Telegram");
                break;

            case "SESSION_PASSWORD_NEEDED":
                exception = new CloudPasswordNeededException("This Account has Cloud Password !");
                break;

            case "AUTH_RESTART":
                ResponseResultSetter.ReturnException(new AuthRestartException());
                return;

            default:
                exception = new InvalidOperationException(error.ErrorMessage);
                break;
            }

            ResponseResultSetter.ReturnException(messageReqMsgId, exception);
        }
Пример #2
0
        private void HandleRpcError(BinaryReader reader, ulong requestId)
        {
            // rpc_error
            var errorCode    = reader.ReadInt32();
            var errorMessage = Serializers.String.Read(reader);

            Log.Warn($"Recieve error from server: {errorMessage}");

            Exception exception;

            if (errorMessage.StartsWith("FLOOD_WAIT_"))
            {
                var resultString = Regex.Match(errorMessage, @"\d+").Value;
                var seconds      = int.Parse(resultString);
                exception = new FloodException(TimeSpan.FromSeconds(seconds));
            }
            else if (errorMessage.StartsWith("PHONE_MIGRATE_"))
            {
                var resultString = Regex.Match(errorMessage, @"\d+").Value;
                var dcIdx        = int.Parse(resultString);
                exception = new PhoneMigrationException(dcIdx);
            }
            else if (errorMessage.StartsWith("FILE_MIGRATE_"))
            {
                var resultString = Regex.Match(errorMessage, @"\d+").Value;
                var dcIdx        = int.Parse(resultString);
                exception = new FileMigrationException(dcIdx);
            }
            else if (errorMessage.StartsWith("USER_MIGRATE_"))
            {
                var resultString = Regex.Match(errorMessage, @"\d+").Value;
                var dcIdx        = int.Parse(resultString);
                exception = new UserMigrationException(dcIdx);
            }
            else if (errorMessage == "PHONE_CODE_INVALID")
            {
                exception = new InvalidPhoneCodeException("The numeric code used to authenticate does not match the numeric code sent by SMS/Telegram");
            }
            else if (errorMessage == "SESSION_PASSWORD_NEEDED")
            {
                exception = new CloudPasswordNeededException("This Account has Cloud Password !");
            }
            else
            {
                exception = new InvalidOperationException(errorMessage);
            }

            ResponseResultSetter.ReturnException(requestId, exception);
        }