Skip to content

Commit 0867c04

Browse files
committed
Handle CONNECTION_NOT_INITED
1 parent 1ecd704 commit 0867c04

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

.github/workflows/dev.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
JSON: |
4848
{
4949
"status": "success", "complete": true, "commitMessage": ${{ toJSON(github.event.head_commit.message) }},
50-
"message": "{ \"commitId\": \"${{ github.event.head_commit.id }}\", \"buildNumber\": \"${{ env.VERSION }}\", \"teamProjectName\": \"${{ github.event.repository.name }}\"}"
50+
"message": "{ \"commitId\": \"${{ github.sha }}\", \"buildNumber\": \"${{ env.VERSION }}\", \"repoName\": \"${{ github.repository }}\"}"
5151
}
5252
run: |
5353
curl -X POST -H "Content-Type: application/json" -d "$JSON" ${{ secrets.DEPLOYED_WEBHOOK }}

src/Client.cs

+27-17
Original file line numberDiff line numberDiff line change
@@ -985,23 +985,7 @@ private async Task DoConnectAsync(bool quickResume)
985985
else
986986
{
987987
if (_dcSession.Layer != 0 && _dcSession.Layer != Layer.Version) _dcSession.Renew();
988-
var initParams = JSONValue.FromJsonElement(System.Text.Json.JsonDocument.Parse(Config("init_params")).RootElement);
989-
TLConfig = await this.InvokeWithLayer(Layer.Version,
990-
new TL.Methods.InitConnection<Config>
991-
{
992-
flags = TL.Methods.InitConnection<Config>.Flags.has_params,
993-
api_id = _session.ApiId,
994-
device_model = Config("device_model"),
995-
system_version = Config("system_version"),
996-
app_version = Config("app_version"),
997-
system_lang_code = Config("system_lang_code"),
998-
lang_pack = Config("lang_pack"),
999-
lang_code = Config("lang_code"),
1000-
params_ = initParams,
1001-
query = new TL.Methods.Help_GetConfig()
1002-
});
1003-
_dcSession.Layer = Layer.Version;
1004-
_session.DcOptions = TLConfig.dc_options;
988+
await InitConnection();
1005989
if (_dcSession.DataCenter == null)
1006990
{
1007991
_dcSession.DataCenter = _session.DcOptions.Where(dc => dc.id == TLConfig.this_dc)
@@ -1022,6 +1006,27 @@ private async Task DoConnectAsync(bool quickResume)
10221006
Helpers.Log(2, $"Connected to {(TLConfig.test_mode ? "Test DC" : "DC")} {TLConfig.this_dc}... {TLConfig.flags & (Config.Flags)~0x18E00U}");
10231007
}
10241008

1009+
private async Task InitConnection()
1010+
{
1011+
var initParams = JSONValue.FromJsonElement(System.Text.Json.JsonDocument.Parse(Config("init_params")).RootElement);
1012+
TLConfig = await this.InvokeWithLayer(Layer.Version,
1013+
new TL.Methods.InitConnection<Config>
1014+
{
1015+
flags = TL.Methods.InitConnection<Config>.Flags.has_params,
1016+
api_id = _session.ApiId,
1017+
device_model = Config("device_model"),
1018+
system_version = Config("system_version"),
1019+
app_version = Config("app_version"),
1020+
system_lang_code = Config("system_lang_code"),
1021+
lang_pack = Config("lang_pack"),
1022+
lang_code = Config("lang_code"),
1023+
params_ = initParams,
1024+
query = new TL.Methods.Help_GetConfig()
1025+
});
1026+
_dcSession.Layer = Layer.Version;
1027+
_session.DcOptions = TLConfig.dc_options;
1028+
}
1029+
10251030
private async Task KeepAlive(CancellationToken ct)
10261031
{
10271032
int ping_id = _random.Next();
@@ -1615,6 +1620,11 @@ public async Task<T> Invoke<T>(IMethod<T> query)
16151620
got503 = true;
16161621
goto retry;
16171622
}
1623+
else if (code == 400 && message == "CONNECTION_NOT_INITED")
1624+
{
1625+
await InitConnection();
1626+
goto retry;
1627+
}
16181628
else if (code == 500 && message == "AUTH_RESTART")
16191629
{
16201630
_session.UserId = 0; // force a full login authorization flow, next time

0 commit comments

Comments
 (0)